9

I am searching for a way to customize (or handle) the 'Enter' of the virtual keyboard when some app user is giving some input in an Android app, for example, when he is pressing "Enter" in an Android app (in some EditText) or when he has completed giving his input, then at that point (or before) can I customize the 'Enter' of the virtual keyboard (like in some apps' virtual keyboard, it is "Done") to text like "Go" etc. Also, if something like some (other) action could also be possibly performed when that virtual keyboard button (like Enter) is being clicked or pressed. Any kind of help would be greatly appreciated.

Android
  • 1,420
  • 4
  • 13
  • 23
Nitin Gurbani
  • 1,220
  • 6
  • 16

2 Answers2

1

You can set different imeOptions like actionDone and actionGo reference link

imeOptions can setted like this in editText

android:imeOptions="actionDone"

to customize these imeActions firstly you can change imeOptions label like this

android:imeActionLabel="@string/anyString"

You have to implements OnEditorActionListener interface and set it to your EditText

editText.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            Toast.makeText(getApplicationContext(), "Your changes have been saved", Toast.LENGTH_SHORT).show();
        }

    }
});
Mustafa Bohra
  • 318
  • 1
  • 11
0

set ImeOptions

et_input.setImeOptions(EditorInfo.IME_ACTION_DONE);

Editor Action Listener

    et_input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            int result = actionId & EditorInfo.IME_MASK_ACTION;

            switch (result) {
                case EditorInfo.IME_ACTION_DONE:

                    break;
                case EditorInfo.IME_ACTION_NEXT:
                    //
                    break;
            }
            return true;
        }
    });
Shomu
  • 2,734
  • 24
  • 32