EditText Properties of Android development

Source: Internet
Author: User
<span id="Label3"></p><p><p><strong>Reprinted from Http://www.cnblogs.com/weixing/p/3257058.html</strong></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p><strong>1</strong> <strong>, edittext the input text is the password form setting</strong></p></p><p><p>(1) Set in. xml:</p></p><p><p>Set the EditText to: android:password= "true"//with "." Form display text</p></p><p><p>(2) set in Code:</p></p><p><p>Implement a hidden password or this display password by setting Edittext's Settransformationmethod () method.</p></p><p><p>Edittext.settransformationmethod (passwordtransformationmethod.getinstance ());//setting The password is not visible.</p></p><p align="left"><p align="left"><strong>2</strong> <strong>, (1) edittext input text is the phone number</strong></p></p><p align="left"><p align="left">android:phonenumber= "true"//enter Phone Number</p></p><p align="left"><p align="left"><strong>3</strong> <strong>, EditText word limit settings</strong></p></p><p><p>(1) set in. xml: android:maxlength= "50"</p></p><p><p>(2) settings in the Code:</p></p><p><p>Edittext.setfilters (new Inputfilter[]{newinputfilter.lengthfilter (100)});</p></p><p><p><strong>4. EditText Setting font</strong></p></p><p><p>Android:typeface= "monospace"//set Font. Glyphs are: normal, sans, serif,monospace</p></p><p align="left"><p align="left"><strong>5</strong> <strong>, whether EditText can be edited</strong></p></p><p><p>Android:editable//is Editable</p></p><p><p><strong>6, the soft keyboard in the edittext, the switch off</strong></p></p><p><p>(1) EditText has focus (focusable is True) prevents Input method pop-up</p></p><p><p>edittext= (editText) Findviewbyid (r.id.txtbody);</p></p><p><p>Edittext.setontouchlistener (new Ontouchlistener () {</p></p><p><p>public boolean OnTouch (View v, motionevent Event) {</p></p><p><p>Edittext.setinputtype (inputtype.type_null); Turn off the soft keyboard</p></p><p><p>Return false;</p></p><p><p>}</p></p><p><p>});</p></p><p><p>(2) Block Input Method popup when Eidttext (focusable=false) is not in focus</p></p><p><p>Inputmethodmanager IMM =</p></p><p><p>(inputmethodmanager) Getsystemservice (input_method_service);</p></p><p><p>Imm.hidesoftinputfromwindow (edittext.getwindowtoken (), 0);</p></p><p><p>(3) call the numeric keypad and set the input type and keyboard to English</p></p><p><p>Etnumber.setinputtype (inputtype.type_class_number); Calling the numeric keypad</p></p><p><p>Rledittext.setinputtype (inputtype.type_text_flag_multi_line);//set input type and keyboard to English or: android:inputtype= "textUri| Textmultiline "</p></p><p><p>(4) android:focusable= "false"//keyboard never pops up</p></p><p><p><activity android:name= ". Addlinkman "android:windowsoftinputmode=" Adjustunspecified|statehidden "/>//does not automatically eject the keyboard</p></p><p><p></p></p><p><p>Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (context.input_method_service) by turning off the keyboard (for example, after the input is finished); Imm.hidesoftinputfromwindow (etedittext.getwindowtoken (), 0);</p></p><p><p></p></p><p><p>Auto Eject keyboard</p></p><p><p>((inputmethodmanager) getsystemservice (input_method_service)). togglesoftinput (0,inputmethodmanager.hide_not_ always);</p></p><p><p>Etedittext.requestfocus ();//let EditText get focus, but get focus does not automatically eject the keyboard</p></p><p><p><strong>7. The difference between android:layout_gravity and android:gravity</strong></p></p><p><p>(1) Android:layout_gravity is the gravity direction of this element to the parent Element.</p></p><p><p>(2) Android:gravity is the gravity direction of all child elements of this Element.</p></p><p align="left"><p align="left"><strong>8</strong> <strong>, android:padding and Android:layout_margin differences</strong></p></p><p><p>Both of these can set margins, but there are subtle differences:</p></p><p><p>(1) android:padding is the margin relative to the parent view</p></p><p><p>(2) Android:layout_margin is relative to the same level view margin</p></p><p><p>Example: LinearLayout is a horizontal layout with two buttons below,</p></p><p><p>(a) if the button on the right side wants to be 15px from the left button, because these two buttons are the same level, should use android:layout_margin;</p></p><p><p>(b) If the right button wants to be 350px from the left, it should be used android:padding</p></p><p><p><strong>9, Android:numeric//only Accept Numbers</strong></p></p><p><p>Android:numeric to control the number type of the input, a total of three kinds are integer (positive integer), signed (signed integer, positive or negative), and decimal (floating point).</p></p><p><p><strong>10. Settings for the ENTER key icon</strong></p></p><p><p>The ENTER key of the soft keyboard displays the "done" text by default, and we know that pressing ENTER indicates that the predecessor work is ready and what to go for. For example, in a search, we enter the text to search for, and then press ENTER to go to search, but the default enter to display the "done" text, looking not very suitable, does not conform to the semantics of the search, if you can display "search" two words or display a search icon is much better. It turns out that our ideas are reasonable and Android also provides us with such features. Change the default "done" text by setting Android:imeoptions. Here are some common constant values:</p></p><p><p>(1) actionunspecified unspecified, corresponding constant editorinfo.ime_action_unspecified effect:</p></p><p><p>(2) actionnone no action, corresponding to the constant Editorinfo.ime_action_none effect:</p></p><p><p>(3) actiongo, corresponding to the constant Editorinfo.ime_action_go effect:</p></p><p><p>(4) Actionsearch search, corresponding to the constant Editorinfo.ime_action_search effect:</p></p><p><p>(5) actionsend send, corresponding constant editorinfo.ime_action_send effect:</p></p><p><p>(6) actionnext next, The corresponding constant Editorinfo.ime_action_next effect:</p></p><p><p>(7) Actiondone complete, corresponding to the constant Editorinfo.ime_action_done effect:</p></p><p><p></p></p><p><p><strong>11. Use Android:imeoptinos to make some interface settings on the android-powered soft keyboard:</strong></p></p><p><p>android:imeoptions= "flagnoextractui"//make The soft keyboard not full-screen, only occupy a portion of the screen at the same time, this property can also control the soft keyboard lower right button display content, by default, Enter the key android:imeoptions= " Actionnone "//input box to the right without any hint android:imeoptions=" Actiongo "//the lower right corner of the key content is ' start ' android:imeoptions= ' Actionsearch '// Lower right button for magnifying glass image, search android:imeoptions= "actionsend"//bottom right button content for ' send ' android:imeoptions= ' actionnext '///lower right corner key content for ' next ' android:imeoptions= "actiondone"//bottom Right button content is ' done '</p></p><p><p><strong>12, limit EditText can enter numbers and letters, and the default input is a number, such as ID card number</strong></p></p><p><p>Android:inputtype= "number" android:digits= "0123456789xyzXYZ"</p></p><p><p><strong>13, The adjustment of the soft keyboard causes the original interface to be squeezed up, or cause the tab navigation below the interface is squeezed up, the solution is as follows</strong></p></p><p><p><strong>Workaround:</strong></p></p><p><p><strong>Use the Android:windowsoftinputmode "adjustpan" property of activity in Manifest.</strong></p></p><p><p><strong>Also note: for problems with soft keyboards, refer to the Android:windowsoftinputmode properties.</strong></p></p><p><p><strong>14, edittext Cursor detailed</strong> Edittext.requestfocusfromtouch ();//let the cursor into the click Position. Edittext.requestfocus ();//the default way to get focus<br>EditText editor = (EditText) getcurrentview ();//the cursor is inserted int cursor = Editor.getselectionstart (); Editor.gettext (). Insert (cursor,delta);</p></p><p><p></p></p><p><p>Let the cursor move to the end (so the text will appear forward) EditText et = ... String Text = "text"; Et.settext (text); Et.setselection (text.length ());</p></p><p><p></p></p><p><p>Android:cursorvisible= "false" to hide the cursor</p></p><p><p>android:background= "#00000000"//don't text Box background</p></p><p><p></p></p><p><p></p></p><span class="link_title"><span class="link_title">Android-input method Control and default focus settings for text boxes</span></span><pre><pre>In the development, the essential will use to the text box (EditText) to carry on the data entry, also will need to have some control to the input method.</pre></pre><pre><pre>First look at the attributes in the layout definition file that are related to the input method:</pre></pre> <table border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <td><pre>Property name</pre></td> <td><pre>Description</pre></td> </tr> <tr> <td><pre>Android:inputtype</pre></td> <td><pre>Specifies the type of input method, int type, which can be selected with | multiple. The value can be referenced by: android.text.InputType class. Values include: text, texturi, phone,number, etc.</pre></td> </tr> <tr> <td><pre>Android:imeoptions</pre></td> <td><pre>Specify the function of Enter key in IME window, the optional value is normal, actionnext,actiondone,actionsearch and so On. Some input methods may not be good enough to support This.</pre></td> </tr> </tbody> </table><pre><pre>The layout definition file below shows some examples of the use of InputType and Imeoptions.</pre></pre><pre><pre><edittextandroid:id= "@+id/textnormal"</pre></pre><pre><pre>Android:layout_width= "fill_parent" android:layout_height= "wrap_content"</pre></pre><pre><pre>Android:hint= "normaltext"</pre></pre><pre><pre>Android:inputtype= "text"</pre></pre><pre><pre>android:imeoptions= "actionnext"</pre></pre><pre><pre>/></pre></pre><pre><pre><edittextandroid:id= "@+id/textinteger"</pre></pre><pre><pre>Android:layout_width= "fill_parent" android:layout_height= "wrap_content"</pre></pre><pre><pre>Android:hint= "integeronly"</pre></pre><pre><pre>Android:inputtype= "number"</pre></pre><pre><pre>android:imeoptions= "actionnext"</pre></pre><pre><pre>/></pre></pre><pre><pre><edittextandroid:id= "@+id/textphone"</pre></pre><pre><pre>Android:layout_width= "fill_parent" android:layout_height= "wrap_content"</pre></pre><pre><pre>Android:hint= "phonenumber"</pre></pre><pre><pre>Android:inputtype= "phone"</pre></pre><pre><pre>android:imeoptions= "actionnext"</pre></pre><pre><pre>/></pre></pre><pre><pre><edittextandroid:id= "@+id/textemail"</pre></pre><pre><pre>Android:layout_width= "fill_parent" android:layout_height= "wrap_content"</pre></pre><pre><pre>Android:hint= "Email"</pre></pre><pre><pre>android:imeoptions= "actionsend"</pre></pre><pre><pre>Android:inputtype= "textemailaddress"</pre></pre><pre><pre>/></pre></pre><pre><pre><edittextandroid:id= "@+id/textsite"</pre></pre><pre><pre>Android:layout_width= "fill_parent" android:layout_height= "wrap_content"</pre></pre><pre><pre>Android:hint= "WebSite"</pre></pre><pre><pre>android:imeoptions= "actiondone"</pre></pre><pre><pre>Android:inputtype= "texturi"</pre></pre><pre><pre>/> sometimes also have to set the default focus of intent, not in the intent jump when the default focus (cursor) on the edittext, leading to enter the intent open input method, affecting the interface Beautiful.</pre></pre><pre><pre>The order of the default focus is the first control that can be entered from the top down from left to right as the focus</pre></pre><pre><pre>You can use:</pre></pre><pre><pre>Button.setfocusable (true);</pre></pre><pre><pre>Button.requestfocus ();</pre></pre><pre><pre>Button.setfocusableintouchmode (true);</pre></pre><pre><pre>You can also:</pre></pre><pre><pre>Put an invisible linearlayout in front of EditText and let him take the lead: <linearlayoutandroid:focusable= "true" android:focusableintouchmode= "true" android:layout_width= "0px" android:layout_height= "0px"/><br>Android EditText Properties Summary</pre></pre><p><p></p></p>Android EditText Properties Summary<p><p></p></p><p><p>android:layout_gravity= "center_vertical" Settings control display location: default top, here is centered, and bottom android:hint= "please enter a number!" "</p></p><p><p>Set the information displayed on the space android:numeric= "integer" setting can only enter an integer, if it is a decimal:</p></p><p><p>Decimal android:singleline= "true" To set the Single-line input, and once set to true, the text is not wrapped automatically.</p></p><p><p>android:password= "true" setting can only enter password</p></p><p><p>Android:textcolor = "#ff8c00" Font Color</p></p><p><p>android:textstyle= "bold" font, bold, italic, bolditalic android:textsize= "20dip" size</p></p><p><p>Android:capitalize = "characters" is written in uppercase letters</p></p><p><p>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</p></p><p><p>android:textcolorhint= "#ffff00" Sets the color of the hint text, the default is gray android:textscalex= "1.5" controls the spacing between words and words</p></p><p><p>android:typeface= "monospace" font, normal, sans, serif, monospace android:background= "@null" space background, not here, refers to transparent</p></p><p><p>android:layout_weight= "1" weights, which control the position between controls, are useful when controlling the size of the control display.</p></p><p><p>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:</p></p><p><p>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.</p></p><p><p>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</p></p><p><p>3. Allow only android:capitalize= "cwj1987" This allows only input cwj1987 to be accepted, generally for password authentication here are some extended style attributes</p></p><p><p>android:editable= "false" setting EditText not editable</p></p><p><p>android:singleline= "true" forces the input to be in a single line</p></p><p><p>Android:ellipsize= "end" automatically hides trailing overflow data, typically used for long lines of text that cannot be displayed all</p></p><p><p>EditText Properties of Android development</p></p></span>

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.