EditText Changes the default text or style by setting the android:imeoptions. Here are some common constant values:
actionunspecified unspecified, corresponding constant editorinfo.ime_action_unspecified.
Actionnone no action, corresponding constant Editorinfo.ime_action_none
Actiongo, corresponding constant Editorinfo.ime_action_go
actionsearch Search, corresponding constant Editorinfo.ime_action_search
actionsend Send, corresponding constant editorinfo.ime_action_send
actionnext Next, corresponding constant Editorinfo.ime_action_next
actiondone complete, corresponding constant Editorinfo.ime_action_done
First of all:
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http// Schemas.android.com/apk/res/android " android:layout_width=" Match_parent " android:layout_height= "50DP" android:orientation= "Horizontal" > <edittext android:id= "@+id/ Searchheaderedit " android:layout_width=" Wrap_content " android:layout_height= "Match_parent" android:drawableright= "@mipmap/icon_search" android:imeoptions= "Actionsearch" android:minwidth= "300DP" android:paddingleft= "10DP" android:singleline= "true" &Nbsp; android:textcolor= "@android: Color/white" android:textsize= "18SP" /></LinearLayout>
which
Android:singleline= "true"
This line is required, and if you do not set a single line, the Imeoptions set will not take effect.
Then by:
Msearchedit.setoneditoractionlistener (New textview.oneditoractionlistener () { @Overridepublic boolean oneditoraction (Textview v, int actionid, keyevent event) { if (actionid == editorinfo.ime_action_ search | | (Event!=null&&event.getkeycode () == keyevent.keycode_enter)) { if (Textutils.isempty (Msearchedit.gettext ())) { msearchedit.requestfocus (); msearchedit.seterror ("Cannot be empty"); }else { //do reseach } return true; } return false;} });
The effect is as follows:
Android change keyboard Enter key text