Search code examples
androidandroid-keypad

change the return key


I want to change the name of enter button (the button circled in the image ) to search

enter image description here

so I used

  <EditText
                android:imeOptions="actionSearch"
                android:imeActionLabel="Search"


                android:id="@+id/et_PatientID"

                android:layout_width="400dip"
                android:layout_height="50dip"
                android:layout_toRightOf="@id/tv_patientID"
                android:background="@android:drawable/editbox_background" />

but it didn't work


Solution

  • add android:imeOptions="actionSearch" and android:inputType="text" to your EditText View

    also add the editor action listener

    editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                performSearch();
                return true;
            }
            return false;
        }
    });
    
    <EditText 
                android:id="@+id/et_PatientID"
                android:inputType="text"
                android:layout_width="400dip"
                android:layout_height="50dip"
                android:layout_toRightOf="@id/tv_patientID"
                android:background="@android:drawable/editbox_background"
                android:imeOptions="actionSearch" 
                android:imeActionLabel="Search"  />