Android:edittext setting properties and setting input rules

Source: Internet
Author: User

1.EditText Input Restriction rules

Setting properties in Xml:edittext

Android:digits= "abcde123&*"

Abcde123&* is your restraining rule.

Example: android:digits= "0123456789ABC"

The rule is to enter only the English alphabet (lowercase) ABC and the number

2.EditTex input text is in password form

(1) Set in XML

Android:password= "true"//with "." Form display text

(2) Set in code

To implement a hidden password and display password by setting the Edittex Settransformationmethod () method

Edittext.settransformationmethod (Passwordtransformationmethod.getinstance ());

Set Password is not visible

3.EditTex input text for phone number

Android:phonenumber= "true"//Enter phone number

4.EditTex Word limit

(1) Set in XML

Android:maxlength= "50"

(2) Set in code

Edittext.setfilters (New Inputfilter[]{newinputfilter.lengthfilter (100)});

5.EditTex is editable

Android:editable= "true"//editable, false not editable

6. Start and close the soft keyboard in the EditText

(1) Edittex has focus (focusable is true) prevents Input method pop-up

Edittext.setontouchlistener (New Ontouchlistener () {

public boolean OnTouch (View view,motionevent event) {

Edittext.setinputtype (input.type_null);//Turn off the soft keyboard

return false;

}});

(2) EditText no focus (focusable=false) when blocking Input method popup

Inputmethodmanager imm= (Inputmethodmanager) Getsystemservice (Input_method_service);

Imm.hidesoftinputfromwindow (Edittext.getwindowtoken (), 0);

(3) Call the numeric keypad and set the input type and keyboard to English

Edittext.setinputtype (Inputtype.type_class_number);//Call the numeric keypad

Edittext.setinputtype (inputtype.type_text_flag_multi_line);//English

(4) keyboard never pops up

Android:focusable= "false"//keyboard never pops up

7. The adjustment of the soft keyboard causes the original interface to be squeezed up, or causes the tab navigation below the interface to be squeezed up, the workaround is as follows

The "Adjustpan" property of Android:windowsfotinputmdoe using activity in Mainfest

Also note: For questions on the soft keyboard, refer to the properties in Android:windowsoftinputmode

8. Cursor explanation

Edittext.requestfocusfromtouch ();//Put the cursor in the click Position

Edittext.requestfocus ();//The default way to get focus

EditText editor= (EditText) Getcurrentview ();//cursor insertion

int Cursor=editor.getselectionstart ();//cursor insertion

Editor.gettext (). inset (Cursor,delta);

Android EditText Properties Summary

android:layout_gravity= "center_vertical" Settings control display location: Default top, here is centered, and bottom android:hint= "Please enter a number!" "

Set the information displayed on the Space android:numeric= "integer" setting can only enter an integer, if it is a decimal:

Decimal android:singleline= "True" to set the single-line input, and once set to True, the text is not wrapped automatically.

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 hint text, the default is gray 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

Android:edittext setting properties and setting input rules

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.