In our phone, although the usual input method soft keyboard will be a return button in the lower right corner, but we often see the click of different edit box, the input method soft keyboard will have a different icon in the lower right corner. For example:
Click on the browser URL bar, the input method soft keyboard in the lower right corner will become "go" or "go;"
And we click on the Google search box, the Input method soft keyboard in the lower right corner will become a magnifying glass or "search".
The parameter that determines the transformation of this icon is the Android:imeoptions attribute in EditText. Android:imeoptions values are Actiongo, Actionsend, Actionsearch, Actiondone, etc.
Set android:imeoptions= "Actiondone", under the soft keyboard becomes "done", after clicking the cursor remains on the original input box, and the soft keyboard is closed.
Android:imeoptions= "Actionsend" under the soft keyboard becomes "send", click on the cursor to move the next.
How to use the Imeoptions set here? As the following code, let EditText implement the Oneditoractionlistener interface, ActionId in the Oneditoraction method corresponds to the imeoptions we set. The system default ActionId are: Editorinfo.ime_null, Editorinfo.ime_action_send, Editorinfo.ime_action_done and so on. In this way, we can implement different soft keyboard lower right corner function keys according to different edittext.
<code class= "Hljs java has-numbering" style= "display:block; padding:0px; Background-color:transparent; Color:inherit; Box-sizing:border-box; font-family: ' Source Code Pro ', monospace;font-size:undefined; White-space:pre; border-top-left-radius:0px; border-top-right-radius:0px; border-bottom-right-radius:0px; border-bottom-left-radius:0px; Word-wrap:normal; Background-position:initial initial; Background-repeat:initial initial; " ><span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >public</span> <span class= "Hljs-class" style= "Box-sizing:border-box;" ><span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >class</span> <span class= "Hljs-title" style= "Box-sizing:border-box; Color:rgb (102, 0, 102); " >IMEOptionsActivity</span> <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >extends</span> <span class= "Hljs-title" style= "Box-sizIng:border-box; Color:rgb (102, 0, 102); " >Activity</span> <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >implements</span> <span class= "Hljs-title" style= "Box-sizing:border-box; Color:rgb (102, 0, 102); " >OnEditorActionListener</span> {</span> EditText Etdone; EditText Etemail; EditText Etnumber; <span class= "hljs-annotation" style= "Color:rgb (155, 133, 157); Box-sizing:border-box; " > @Override </span> <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >public</span> <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >void</span> <span class= "Hljs-title" style= "Box-sizing:border-box;" >onCreate</span> (Bundle savedinstancestate) {<span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136) ; Box-sizing:border-box; " >super</span>.oncreate (savedinstancestate); SEtcontentview (r.layout.imf_layout); Etdone= (EditText) Findviewbyid (r.id.done_content); Etemail = (EditText) Findviewbyid (r.id.email_content); Etnumber = (EditText) Findviewbyid (r.id.number_content); Etdone.setoneditoractionlistener (<span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); box-sizing:border-box;" >this</span>); Etemail.setoneditoractionlistener (<span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); box-sizing:border-box;" >this</span>); Etnumber.setoneditoractionlistener (<span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box ;" >this</span>); } <span class= "Hljs-annotation" style= "Color:rgb (155, 133, 157); Box-sizing:border-box; " > @Override </span> <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >public</span> <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-bOx; " >boolean</span> <span class= "Hljs-title" style= "Box-sizing:border-box;" >onEditorAction</span> (TextView V, <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing: Border-box; " >int</span> ActionId, KeyEvent event) {<span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); box- Sizing:border-box; " >switch</span> (ActionId) {<span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border -box; " >case</span> EditorInfo.IME_NULL:System.out.println (<span class= "hljs-string" style= "Color:rgb ( 0, 136, 0); Box-sizing:border-box; " > "Done_content:" </span> + V.gettext ()); <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >break</span>; <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >case</span> EditorInfo.IME_ACTION_SEND:System.out.println (<spanclass= "hljs-string" style= "Color:rgb (0, 136, 0); Box-sizing:border-box; " > "Send a Email:" </span> + V.gettext ()); <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >break</span>; <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >case</span> EditorInfo.IME_ACTION_DONE:System.out.println (<span class= "hljs-string" style= "Colo R:rgb (0, 136, 0); Box-sizing:border-box; " > "Action done for Number_content:" </span> + V.gettext ()); <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >break</span>; } <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >return</span> <span class= "Hljs-keyword" style= "Color:rgb (0, 0, 136); Box-sizing:border-box; " >true</span>; }} </code>
Android EditText imeoptions attribute parsing