Search code examples
androidandroid-softkeyboardandroid-keypadandroid-version

Show 'Done' key on softkeyboard


I need the softkeyboard to display the 'Done' key when inputting text into an EditText in my application. On an Android 2.1 device the 'Done' button is displayed, but not on 2.3 or it higher.

This is the code I use:

    e.setImeOptions(EditorInfo.IME_ACTION_DONE);

    e.setOnEditorActionListener(
            new EditText.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId,KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_SEARCH ||
                            actionId == EditorInfo.IME_ACTION_DONE ||
                            event.getAction() == KeyEvent.ACTION_DOWN &&
                            event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                        Toast.makeText(getBaseContext(), e.getText().toString(), Toast.LENGTH_SHORT).show();

                        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(e.getWindowToken(), 0);

                        return true;
                    }
                    return false;
                }
            });

I am using a samsung device with Android version 2.3.4.

Screenshort of the edittext:

enter image description here


Solution

  • It is not Android version's fault, but the IME your device use. Samsung (and some of HTC, I think) IME never change the letter to "Done" or "Next" or "Go".