Android Internship notes (1)---edittext properties imeoption detailed
1) What does this attribute do?
A : When we enter a UI control that can enter text, such as EditText, the popup Small Keyboard of the
the lower right corner of the Enter key ! You heard it wrong, this property is about the ENTER key!!!
we can pass Imeoption Property come to set the contents of the ENTER key to display , and for event monitoring ~
2) How to modify the content displayed by the ENTER key:
A: Directly set the Imeoption property, in addition, using a third-party input method may appear different results,
Or did not change, here only Sogou input method for reference, the other is ignored!
All you need to do is add the Imeoption attribute to the EditText! In addition, if you need to set it in Java code, call the
Setimeoption method, then the parameter actionsearch only need to change to: Editorinfo.ime_action_search can
And so on
<edittext android:id= "@+id/editsearch" android:layout_width= "match_parent" android:layout_ height= "Wrap_content" android:imeoptions= "Actionsearch" android:text= "actionsearch, Query" android: Singleline= "true" />
After the test, the following:
① Original Input Method/Sogou Input Method
actionunspecified:~ ~ ~
Actionnone:~ ~ ~
actiongo:~~~
actionsearch:~~~
actionsend:~~~
actionnext:~~~
actiondone:~~~
!!! Another problem is that if your system version is above 2.3, it is possible that this property is set, but it has no effect;
We only need to set Singleline to True for EditText or inputtype to text!!!
3) Capture the Click event of the ENTER key
This is also very simple, just set the event listener for EditText:setoneditoractionlistener , then
Rewrite the oneditoraction (TextView v, int ActionId, KeyEvent event) method,
Then according to your needs, corresponding to the ENTER key in what state, respond to the corresponding event, very simple, the sample code is as follows:
Note that pressing the ENTER key will trigger this event !
Public Oneditoractionlistener Editoractionlistener = new Oneditoractionlistener () {@Overridepublic Boolean Oneditoraction (TextView v, int ActionId, keyevent event) {if (ActionId = = editorinfo.ime_action_unspecified) { Toast.maketext (Getapplicationcontext (), "No Effect", Toast.length_short). Show (); else if (ActionId = = Editorinfo.ime_action_search) {Toast.maketext (Getapplicationcontext (), "Query", Toast.length_short) . Show (); return false;}};
4) Test demo Download:
Go back and give it.
As follows:
Android Internship notes (1)---edittext properties imeoption detailed