1, enter the input key icon settings:
The interface of the software disk is replaced with only one attribute android:imeoptions, the value of this property can be Normal,actionunspecified,actionnone,actiongo,actionsearch, Actionsend,actionnext,actiondone, For example, the Enter key appearance becomes a down arrow when the value is Actionnext, and the ENTER key looks like a "complete" two characters when the values are actiondone.
We can also override the Enter event
The ENTER key of the soft keyboard displays the "Done" text by default, and the default "Finish" text is changed by setting Android:imeoptions. Here are some common constant values:
actionunspecified unspecified, corresponding constant editorinfo.ime_action_unspecified.
Actionnone no action, corresponding constant Editorinfo.ime_action_none
Actiongo, corresponding constant editorinfo.ime_action_go
Actionsearch search, corresponding constant editorinfo.ime_action_search
Actionsend send, corresponding constant editorinfo.ime_action_send
Actionnext Next, corresponding constant Editorinfo.ime_action_next
Actiondone complete, corresponding constant Editorinfo.ime_action_done
(Editorinfo.inputtype & Editorinfo.type_class_mask) can be a number of different values, including:
Type_class_number
Type_class_datetime
Type_class_phone
Type_class_text
2, Event capture processing:
Event handling can be set through Setoneditoractionlistener.
Final EditText input = new EditText (this); Input.setsingleline (TRUE); Android:singleline= "true" input.setimeoptions (editorinfo.ime_action_send); Input.setinputtype (Inputtype.type_class_text | Inputtype.type_text_variation_password); Input.setoneditoractionlistener (New Textview.oneditoractionlistener () {public Boolean oneditoraction (TextView V, int ActionId, keyevent event) { log.d (TAG, "" +actionid+ "," +event "); if (Actionid==editorinfo.ime_action_send | | (Event!=null&&event.getkeycode () = = Keyevent.keycode_enter)) { //do something; return true; } return false; }
3, editor password hidden, how to write?
There are 2 ways to handle:
Code method: Input.setinputtype (Inputtype.type_class_text | Inputtype.type_text_variation_password);
Layout Configuration method: Android:inputtype= "Textpassword"
4. When the activity is loaded, the Edit input box will automatically eject the input method, which can be masked by the following code:
GetWindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
5, set EditText always does not eject the software keyboard
Example: EditText edit= (EditText) Findviewbyid (R.id.edit);
Edit.setinputtype (Inputtype.type_null);
6, let EditText lose focus, use EditText Clearfocus method
For example: EditText edit= (EditText) Findviewbyid (R.id.edit);
Edit.clearfocus ();
7, edittext default does not eject the software keyboard
Select activity in Androidmainfest.xml, set Windowsoftinputmode property to Adjustunspecified|statehidden
< activity android:name= ". Main "android:label=" @string/app_name "android:windowsoftinputmode=" Adjustunspecified|statehidden "Android: Configchanges= "Orientation|keyboardhidden" >< intent-filter>< action android:name= " Android.intent.action.MAIN "/>< category android:name=" Android.intent.category.LAUNCHER "/></ intent-filter></activity>
8. Set the cursor to the specified position
EditText et = (EditText) Findviewbyid (r.id.ettest); et.setselection (2);
//setting cursor does not display, but cannot set cursor color
Et. Setcursorvisiblefalse
//Get focus Full text
Et.true
ET. requestfocus (;&NBSP; //request to get focus
ET. clearfocus (; / /clear Focus
Use edittext seterror hint
Et. seterror("email")
SetError Tips for customizing icons
Drawable dr = Getresources (). getdrawable (R.drawable.ic_launcher);d r.setbounds (0, 0, 10, 10); The size must be set, otherwise the Et.seterror ("with Error Prompt", DR) is not displayed;
et. Setinputtype ; You can only enter the phone number
Et. //Enter only numbers
Et.;//can only enter e-mail address
Et.; //forbidden Input (Input Method not popup)
XML Implementation Case
<edittext android:id= "@+id/ettest" android:inputtype= "number" android:layout_width= "Wrap_content " android:layout_height= "Wrap_content"/>
8. EditText Related attributes
EditText inheritance Relationship: View-->textview-->edittext.
EditText has a lot of properties, here are a few:
Android:layout_gravity= "Center_vertical"
Sets the location of the control's display: Default top, centered here, and bottom
Android:hint= "Please enter a number! "
Set up a message to display on space
Android:numeric= "Integer"
The setting can only enter integers, if it is a decimal: decimal
Android:singleline= "true"
Sets the single-line input, and once set to True, the text is not wrapped automatically.
Android:password= "true"
Set to enter password only
Android:textcolor = "#ff8c00"
Font Color
Android:textstyle= "Bold"
Font, bold, italic, Bolditalic
Android:textsize= "20dip"
Size
Android:capitalize = "Characters"
Write in uppercase letters
android:textalign= "Center"
EditText does not have this attribute, but TextView has, centered
android:textcolorhighlight= "#cccccc"
The background of the selected text, which is blue by default
Android:textcolorhint= "#ffff00"
Sets the color of the message text, which is grayed out by default
android:textscalex= "1.5"
Control the spacing between words and words
Android:typeface= "Monospace"
Font, normal, sans, serif, monospace
Android:background= "@null"
Space background, not here, refers to transparent
android:layout_weight= "1"
Weights, which control the position between controls, are useful when controlling the size of the control display.
Android:textappearance= "? Android:attr/textappearancelargeinverse"
Android edittext Settings (RPM)