Android Internship notes (1)---edittext properties imeoption detailed

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.