In this article, IME(Input Method Action) Option is changed in android according to our requirement. Input Method Action Button is located in the bottom right corner of the soft keyboard. By default, the system uses this button for either a Next or Done action unless your text field allows multi-line text, in which case the action button is a carriage return. However, you can specify additional actions that might be more appropriate for your text fields, such as Go, Send, Previous, None, etc. The IME option for Next and Done are shown below.
Â
- Action Next
- Action Done
- Add the following code in activity_main.xml file.In this file we specify IME option to the EditText according to the need. Here an imageview and two edittexts are added and and IME option is specified for actionDone.
activity_main.xml
<?xmlversion="1.0"encoding="utf-8"?><LinearLayout   Âandroid:layout_width="match_parent"   Âandroid:layout_height="match_parent"   Âandroid:orientation="vertical"   Âtools:context=".MainActivity">   Â<ImageView       Âandroid:layout_gravity="center"       Âandroid:layout_marginTop="50dp"       Âandroid:layout_width="200dp"       Âandroid:layout_height="200dp"       Âandroid:src="@drawable/gfg"       Â/>   Â<EditText       Âandroid:layout_marginTop="50dp"       Âandroid:layout_marginStart="10dp"       Âandroid:layout_marginEnd="10dp"       Âandroid:id="@+id/editText1"       Âandroid:layout_width="match_parent"       Âandroid:layout_height="wrap_content"       Âandroid:hint="Username"       Âandroid:paddingBottom="20dp"       Âandroid:inputType="text"/>   Â<EditText       Âandroid:paddingTop="20dp"       Âandroid:layout_margin="10dp"       Âandroid:id="@+id/editText2"       Âandroid:layout_width="match_parent"       Âandroid:layout_height="wrap_content"       Âandroid:hint="Password"       Âandroid:imeOptions="actionDone"       Âandroid:inputType="textPassword"/>ÂÂ</LinearLayout>
Now add the following code in MainActivity.java file. In this file we add listener to our EditText which will correspond to our action accordingly. Here we override onEditorAction method and show toast for ACTION DONE and ACTION NEXT IME options.
MainActivity.java
packageorg.neveropen.imeoption;ÂÂimportandroidx.appcompat.app.AppCompatActivity;importandroid.os.Bundle;importandroid.view.KeyEvent;importandroid.view.inputmethod.EditorInfo;importandroid.widget.EditText;importandroid.widget.TextView;importandroid.widget.Toast;ÂÂpublicclassMainActivityextendsAppCompatActivity {   Â@Override   ÂprotectedvoidonCreate(Bundle savedInstanceState)   Â{       Âsuper.onCreate(savedInstanceState);       ÂsetContentView(R.layout.activity_main);       ÂEditText login = findViewById(R.id.editText1);       ÂEditText password = findViewById(R.id.editText2);       Âlogin.setOnEditorActionListener(actionListener);       Âpassword.setOnEditorActionListener(actionListener);   Â}   Â// whenever the user clicks on IME button this listener will   Â// get invoked automatically.   ÂprivateTextView.OnEditorActionListener actionListener       Â=newTextView.OnEditorActionListener() {             Â@Override             ÂpublicbooleanonEditorAction(TextView v,                                           ÂintactionId, KeyEvent event)             Â{                 Âswitch(actionId) {                 ÂcaseEditorInfo.IME_ACTION_NEXT:                     ÂToast.makeText(MainActivity.this,                                    Â"Next", Toast.LENGTH_SHORT)                         Â.show();                     Âbreak;                 ÂcaseEditorInfo.IME_ACTION_DONE:                     ÂToast.makeText(MainActivity.this,                                    Â"Login", Toast.LENGTH_SHORT)                         Â.show();                     Âbreak;                 Â}                 Âreturnfalse;             Â}         Â};} - Add the following code in activity_main.xml file.In this file we specify IME option to the EditText according to the need. Here an imageview and two edittexts are added and and IME option is specified for actionDone.
