By default, the button in the lower-right corner of the soft keyboard is "next" and the next input box is clicked to keep the soft keyboard
Set android:imeoptions="Actiondone" , under the soft keyboard becomes "done", click the cursor remains on the original input box, and the soft keyboard off
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 Setoneditoractionlistener, ActionId in the Oneditaction 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.
Java code
- Package com.test;
- Import Com.test.main.TestAsyn;
- Import android.app.Activity;
- Import Android.os.Bundle;
- Import android.view.KeyEvent;
- Import Android.view.inputmethod.EditorInfo;
- Import Android.widget.EditText;
- Import Android.widget.TextView;
- Import Android.widget.TextView.OnEditorActionListener;
- Import Android.widget.Toast;
- Public class Imfactivity extends Activity implements Oneditoractionlistener {
- EditText Etdefault;
- EditText Etemail;
- EditText Etnumber;
- /** Called when the activity is first created. * /
- @Override
- public void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- Setcontentview (r.layout.imf_layout);
- Etdefault = (EditText) Findviewbyid (r.id.default_content);
- Etemail = (EditText) Findviewbyid (r.id.email_content);
- Etnumber = (EditText) Findviewbyid (r.id.number_content);
- Etdefault.setoneditoractionlistener (this);
- Etemail.setoneditoractionlistener (this);
- Etnumber.setoneditoractionlistener (this);
- }
- @Override
- Public Boolean oneditoraction (TextView V, int ActionId, keyevent event) {
- switch (actionid) {
- Case Editorinfo.ime_null:
- SYSTEM.OUT.PRINTLN ("Null for default_content:" + v.gettext ());
- Break ;
- Case Editorinfo.ime_action_send:
- System.out.println ("Action Send for Email_content:" + v.gettext ());
- Break ;
- Case Editorinfo.ime_action_done:
- System.out.println ("Action done for Number_content:" + v.gettext ());
- Break ;
- }
- //toast.maketext (this, v.gettext () + "--" + ActionId, Toast.length_long). Show ();
- return true;
- }
- }
XML file:
XML code
- <? XML version= "1.0" encoding="Utf-8"?>
- <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width= "fill_parent" android:layout_height="fill_parent">
- <tablelayout android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <TableRow>
- <TextView android:text="No special rules" android:id="@+id/textview01 "
- android:layout_width= "wrap_content" android:layout_height="wrap_content"></ TextView>
- <EditText android:text="1111111111111" android:id="@+id/default_content "
- android:layout_width= "fill_parent" android:layout_height="wrap_content"></ EditText>
- </TableRow>
- <TableRow>
- <TextView android:text="Email address:" android:id="@+id/textview01"
- android:layout_width= "wrap_content" android:layout_height="wrap_content"></ TextView>
- <EditText android:text= "" android:id= "@+id/email_content"
- android:layout_width= "fill_parent" android:layout_height="wrap_content "
- android:inputtype="text|textemailaddress"
- android:imeoptions="Actionsend"></EditText>
- </TableRow>
- <TableRow>
- <TextView android:text="Signed decimal number:" android:id="@+id/textview01"
- android:layout_width= "wrap_content" android:layout_height="wrap_content"></ TextView>
- <EditText android:text= "" android:id= "@+id/number_content"
- android:layout_width= "fill_parent" android:layout_height="wrap_content "
- android:inputtype="Number|numbersigned|numberdecimal"
- android:imeoptions="Actiondone"></EditText>
- </TableRow>
- </tablelayout>
- </ScrollView>
Turn from:
http://liliang1222.iteye.com/blog/1130062
(GO) Android:imeoptions property