Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to customize the 'Enter' of the virtual keyboard when giving input in an Android app and also handle its click action?

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.

like image 874
Nitin Gurbani Avatar asked Aug 08 '18 08:08

Nitin Gurbani


1 Answers

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();
        }

    }
});
like image 168
Mustafa Bohra Avatar answered Sep 21 '22 17:09

Mustafa Bohra