Last week look at a company project flexible use of the EditText attribute InputType. The InputType property can be defined not only in XML. It can also be set in the activity. This is how the project scenario applies. A page requires a lot of dialog input, including the need for character type, digital type, or password input. But only a pop-up dialog box is made, and then different calls to this dialog box, with a unique code to identify that button call popup. Then pop out the dialog box (input type) to be set flexibly. It is necessary to set the property value for activity passing inputtype. Because this dialog box calls only one XML. This is a scene.
First, talk about the XML inside the call, this is not unfamiliar to say.
<edittext android:id= "@+id/edittext" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:inputtype= "number"/>
Here is the number.
Second, the call in the activity. or other class.
EditText Testedittext = (EditText) Findviewbyid (r.id.edittext); int inputtype = Inputtype.type_class_number | Inputtype.type_number_variation_normal;testedittext.setinputtype (InputType);
This inputtype value is not very useful ah. It's flexible!
Then I map to see the source of InputType attribute class bar. Such as
This above is inputype all attributes, these more look, are English words.
Third, by the way, the value of XML InputType.
android:inputtype= "None"
android:inputtype= "Text"
android:inputtype= "textcapcharacters" letter capitalization
android:inputtype= "Textcapwords" first letter capitalization
android:inputtype= "Textcapsentences" only the first letter of capitalization
android:inputtype= "Textautocorrect" auto-complete
android:inputtype= "Textautocomplete" auto-complete
android:inputtype= "Textmultiline" multi-line input
android:inputtype= "Textimemultiline" Input method multiple lines (if supported)
android:inputtype= "Textnosuggestions" does not prompt
android:inputtype= "Texturi" url
android:inputtype= "textemailaddress" email address
android:inputtype= "textemailsubject" message subject
android:inputtype= "Textshortmessage" SMS
android:inputtype= "textlongmessage" long message
android:inputtype= "Textpersonname" name
android:inputtype= "textpostaladdress" Address
android:inputtype= "Textpassword" Password
android:inputtype= "Textvisiblepassword" Visible password
android:inputtype= "Textwebedittext" as the text of a Web Form
android:inputtype= "TextFilter" Text filter filter
android:inputtype= "textphonetic" Pinyin input
//numeric type
android:inputtype= "number" numbers
android:inputtype= "numbersigned" signed number format
android:inputtype= "Numberdecimal" floating-point format with decimal point
android:inputtype= "Phone" dial pad
android:inputtype= "datetime" Time Date
android:inputtype= "date" dates keyboard
android:inputtype= "Time" keyboard
Iv. Introduction EditText Other Common properties, collected on the network.
android:layout_gravity= "center_vertical" Settings control display location: Default top, here is centered, and bottom android:hint= "Please enter a number!" "Sets the prompt information displayed on the space
The android:numeric= "integer" 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 does not wrap.
Android:password= "true" setting can only enter password
Android:textcolor = "#ff8c00" Font Color
android:textstyle= "bold" font, bold, italic, Bolditalic
Android:textsize= "20dip" size
Android:capitalize = "Characters" is written in uppercase letters
android:textalign= "center" EditText does not have this attribute, but TextView has android:textcolorhighlight= "#cccccc" is the background of the selected text, the default is blue
Android:textcolorhint= "#ffff00" sets the color of the message text, which is grayed out by default
android:textscalex= "1.5" controls 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" text appearance, here refers to the system comes with a look,? Indicates whether the system has this appearance, otherwise the default appearance is used. I don't know if I understand that, right?
Implemented by edittext the relevant properties in the layout XML file:
1. The Password Box property android:password= "True" allows the EditText to be displayed automatically as an asterisk, and the content will be changed to * within 1 seconds.
2. Pure Digital android:numeric= "true" This allows the input method to automatically become a digital input keyboard, while allowing only 0-9 of the digital input
3. Allow only android:capitalize= "cwj1987" This allows only input cwj1987 to be accepted, generally for password authentication here are some extended style attributes
Android:editable= "false" setting EditText not editable
Android:singleline= "true" forces the input to be in a single line
Android:ellipsize= "End" automatically hides trailing overflow data, typically used for long lines of text that cannot be displayed all
Although these are very simple, but also very common. The details need attention in order to achieve the ultimate.
Android EditText Properties InputType detailed