setImeOptions: why the “Done” button does not show on the soft keyboard?

微笑、不失礼 提交于 2019-12-03 08:16:58

问题


I try to set the "Done" button on the softkeyboard by using input.setImeOptions(EditorInfo.IME_ACTION_DONE);

but the "Done" button simply does not show on the softkeyboard.

Any suggestion please?

public void modif(int position) {
    AlertDialog.Builder alert = new  AlertDialog.Builder(MainActivity.this);
    alert.setTitle("Modifica");
    EditText input = new EditText(MainActivity.this);
    input.setImeOptions(EditorInfo.IME_ACTION_DONE);
    alert.setView(input);
    final Editable value = input.getText();
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {  
        public void onClick(DialogInterface dialog, int whichButton) {
            Toast.makeText(getApplicationContext(), value,   Toast.LENGTH_LONG).show();
        }
    });

    alert.setNegativeButton("Cancel", new     DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
        // Canceled.
        }
    });
    alert.show();                   
}

回答1:


It's probably because your input field is not single-lined.

Try adding

input.setSingleLine();

And you will see that pressing the action key of the keyboard will actually perform a 'done' action (i.e close the keyboard)

See http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_DONE



来源:https://stackoverflow.com/questions/13561808/setimeoptions-why-the-done-button-does-not-show-on-the-soft-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!