For Android devices, there may be no physical keyboard, a keyboard, or a digital keyboard, which can be processed.
InputType: IME can automatically adapt to the specified input type
If there is no physical keyboard, IME (Imput Method Editor) will be triggered when the user enters edittext ). In general, IME is smart and does not need to be processed. However, in some specific situations, for example, in a multi-row edittext, IME will cover part of the content. At this time, we need to consider it. In addition, there are password input, restriction type input (number, phone OK, date, time, etc.), you can set through Android: inputtype, inputtype can set multiple attributes, "|" is used for separation. There should be no space between "|" and "|. The following is an example:
<? Xml version = "1.0" encoding = "UTF-8"?>
<TableLayout... android: stretchColumns = "1">
<TableRow>
<TextView android: text = "No Special rules:"/>
<EditText/> <! -- InputType: The default value is text. -->
</TableRow>
<TableRow>
<TextView android: text = "Email address:"/>
<EditTextAndroid: inputType = "text | textEmailAddress"/>
</TableRow>
<TableRow>
<TextView android: text = "Signed decimal number:"/>
<EditTextAndroid: inputType = "number | numberSigned | numberDecimal"/>
</TableRow>
<TableRow>
<TextView android: text = "Date:"/>
<EditTextAndroid: inputType = "date"/>
</TableRow>
<TableRow>
<TextView android: text = "Multi-line text:"/>
<EditTextAndroid: inputType = "text | textMultiLine | textAutoCorrect"
Android: minLines = "3" android: gravity = "top"/>
</TableRow>
</TableLayout>
The IME provided in begining book is different from my simulator. The simulator uses the T9 numeric keyboard mode. Due to the different display requirements, therefore, the appearance of the keyboard may be different. See the following two figures:
IME can trigger an event through the validation key
In the lower-right corner, the button becomes the accessory button, that is, the validation key. We can set related processing through Android: imeoptions, for example:
<TextView android: text = "Signed decimal number:"/>
<EditText android: inputType = "number | numberSigned | numberDecimal"
Android: imeOptions ="ActionDone"/>
By default, pressing the accessroy button will focus on the next edittext, but we can customize this text. For example, in the preceding example, when we press the OK key, the ime keyboard disappears, indicating that the ime process is complete. Let's look at another example:
<EditText android: id = "@ + id/c10_send"
Android: inputType = "text | textEmailAddress"
Android: imeOptions = "actionSend"/>
This is an email address format. We hope that the user can trigger it after pressing the ime validation key. in the program, we can monitor the ime_action_send actionid. :
TextView edit = (TextView) findViewById (R. id. c10_send );
Edit.Setoneditexceptionlistener(New TextView. oneditexceptionlistener ()
{
Public booleanOneditexception(TextView v, int actionId, KeyEvent event ){
If (actionId =EditorInfo. IME_ACTION_SEND)
Log. d ("WEI", "Receive ime: IME_ACTION_SEND ");
Return false;
}
});
IME adaptation
In the above example, if we click the first edittext, IME overlay the bottom widget. If we click the bottom edittext, the entire layout will go up to scroll, this becomes the pan adaptation mode. Android can resize our acitivity to make it smaller so that the ime can be under the activity. This is resize adaptation. In Landscape mode, Android may overwrite the entire acivity with full screen IME, which allows you to enter a larger soft keyboard.
Generally, Android will select the pan or resize mode based on layout. If you need to specify the pan mode, you can go to AndroidManifest. set the android: windowSoftInputMode attribute in acivity in the xml file. The following is an example:
<Activity android: name = ". Chapter10.Chapter10Test2" android: label = "@ string/chapter_10_test2"
Android: windowSoftInputMode = "adjustResize"/>
We will show android: minLines = "5" in the last EditText in the above example to make it have a larger space. The following two figures use the default mode on the left and the right, android: windowSoftInputMode = "adjustResize" is required.
Related Links: My Andriod development articles