EditText properties of "turn" Android development

Source: Internet
Author: User

Original URL: http://blog.csdn.net/qq435757399/article/details/7947862

1 , edittext the input text is the password form setting

(1) Set in. xml:

Set the EditText to: android:password= "true"//with "." Form display text

(2) Set in code:

Implement a hidden password or this display password by setting EditText's Settransformationmethod () method.

Edittext.settransformationmethod (Passwordtransformationmethod.getinstance ());//Setting the password is not visible.

2 , (1) edittext input text is the phone number

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

3 , EditText word limit settings

(1) Set in. xml: Android:maxlength= "50"

(2) settings in the code:

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

4. EditText Setting font

Android:typeface= "monospace"//Set font. Glyphs are: normal, sans, serif,monospace

5 , whether EditText can be edited

Android:editable//Is editable

6, the soft keyboard in the EditText, the switch off

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

edittext= (EditText) Findviewbyid (r.id.txtbody);

Edittext.setontouchlistener (New Ontouchlistener () {

public boolean OnTouch (View V, motionevent event) {

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

return false;

}

});

(2) block Input Method popup when Eidttext (Focusable=false) is not in focus

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

Etnumber.setinputtype (Inputtype.type_class_number); Calling the numeric keypad

Rledittext.setinputtype (inputtype.type_text_flag_multi_line);//Set input type and keyboard for English
Or: android:inputtype= "Texturi|textmultiline"

(4) android:focusable= "false"//keyboard never pops up


<activity android:name= ". Addlinkman "android:windowsoftinputmode=" Adjustunspecified|statehidden "/>//does not automatically eject the keyboard

Close the keyboard (for example, after the input is finished)
Inputmethodmanager IMM = (inputmethodmanager) getsystemservice (Context.input_method_service);
Imm.hidesoftinputfromwindow (Etedittext.getwindowtoken (), 0);

Auto Eject keyboard

((Inputmethodmanager) Getsystemservice (Input_method_service)). Togglesoftinput (0,inputmethodmanager.hide_not_ Always);

Etedittext.requestfocus ();//Let EditText get focus, but get focus does not automatically eject the keyboard

7. The difference between android:layout_gravity and android:gravity

(1) android:layout_gravity is the gravity direction of this element to the parent element.

(2) android:gravity is the gravity direction of all child elements of this element.

8 , android:padding and Android:layout_margin differences

Both of these can set margins, but there are subtle differences:

(1) android:padding is the margin relative to the parent view

(2) Android:layout_margin is relative to the same level view margin

Example: LinearLayout is a horizontal layout with two buttons below,

(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;

(b) If the right button wants to be 350px from the left, it should be used android:padding

9, android:numeric//only accept numbers

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).

10. Settings for the ENTER key icon

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:

(1) actionunspecified unspecified, corresponding constant editorinfo.ime_action_unspecified effect:

(2) Actionnone no action, corresponding to the constant Editorinfo.ime_action_none effect:

(3) Actiongo, corresponding to the constant Editorinfo.ime_action_go effect:

(4) Actionsearch search, corresponding to the constant Editorinfo.ime_action_search effect:

(5) Actionsend send, corresponding constant Editorinfo.ime_action_send effect:

(6) Actionnext Next, the corresponding constant Editorinfo.ime_action_next effect:

(7) Actiondone complete, corresponding to the constant Editorinfo.ime_action_done effect:

11. Use Android:imeoptinos to make some interface settings on the Android-powered soft keyboard:

android:imeoptions= "Flagnoextractui"//Make soft keyboard not full screen, only occupy part of the screen
This property also controls the display of keys in the lower right corner of the soft keyboard, which is the return key by default.
android:imeoptions= "Actionnone"//input box to the right without any hint
android:imeoptions= "Actiongo"//Bottom right button content is ' start '
android:imeoptions= "Actionsearch"//Bottom right button for magnifying glass image, search
android:imeoptions= "Actionsend"//lower right button content for ' send '
android:imeoptions= "Actionnext"//lower right button content for ' next '
android:imeoptions= "Actiondone"//Bottom right button content is ' done '

12, limit edittext can enter numbers and letters, and the default input is a number, such as ID card number

Android:inputtype= "Number"
Android:digits= "0123456789xyzXYZ"

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

Workaround:

Use the Android:windowsoftinputmode "Adjustpan" property of activity in manifest.

Also note: For problems with soft keyboards, refer to the Android:windowsoftinputmode properties.

14, EditText Cursor detailed
Edittext.requestfocusfromtouch ();//Let the cursor be placed in the click position.
Edittext.requestfocus ();//The default way to get focus

EditText editor = (EditText) getcurrentview ();//insertion at cursor
int cursor = Editor.getselectionstart ();
Editor.gettext (). Insert (Cursor,delta);

Let the cursor move to the end (so the text will be displayed forward)
EditText et = ...
String Text = "text";
Et.settext (text);
Et.setselection (Text.length ());

Android:cursorvisible= "false" to hide the cursor

Android:background= "#00000000"//Don't text box background

Original URL: http://liangruijun.blog.51cto.com/3061169/627350

Original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://liangruijun.blog.51cto.com/3061169/627350

EditText inherit TextView, so edittext has TextView attribute characteristics, the following mainly introduces some edittext characteristics of the unique Input method properties

Android:layout_gravity= "Center_vertical": Sets the location where the control is displayed: Default top, centered here, and bottom

Android:hin: Text message is displayed when text is empty, and you can set the color of the cue message by Textcolorhint. Android:singleline: Set single-line input, once set toTrue, the text is not wrapped automatically. android:gray= "Top": pointer in multiple rows first position in first rowEt.setselection (Et.length ());: Adjusts the cursor to the last lineAndroid:autotext: automatic spelling help. The individual settings here are not effective and may require additional input method assistance .Android:capitalize: Sets the English letter capitalization type. Set the following values: Sentences only the first letter of the uppercase, words each word the first letter size, with a space to distinguish between words; characters each English letter is capitalized. Android:digits: Sets which characters are allowed to be entered. such as "1234567890.+-*/%\n ()"Android:singleline: Whether a single line or multiple rows, enter is to leave the text box or text box to add new linesAndroid:numeric: If set, the TextView receives a digital input. The following values are set: Integer positive integer, signed signed integer, decimal with decimal point floating point number. Android:inputtype: Sets the type of text Android:password: password, to dot "." Display textAndroid:phonenumber: Sets the input method for the phone number. Android:editable: Sets whether it can be edited. You can still get the cursor, but you cannot enter it. android:autolink= "All": Set the text hyperlink style when you click the URL, skip to the URLAndroid:textcolor = "#ff8c00": Font ColorAndroid:textstyle= "Bold": Font,Bold, italic, bolditalicandroid:textalign= "center":EditTextwithout this attribute, butTextViewhave aandroid:textcolorhighlight= "#cccccc": The background of the selected text, the default is blueAndroid:textcolorhint= "#ffff00": Sets the color of the message text, which is grayed out by defaultandroid:textscalex= "1.5": Controls the spacing between words and wordsAndroid:typeface= "Monospace": Font,Normal, sans, serif, monospaceandroid:background= "@null": space background, not here, refers to transparentandroid:layout_weight= "1": Weights are useful when controlling the size of the control display. Android:textappearance= "? Android:attr/textappearancelargeinverse": text appearance, which refers to the system comes with a look,? Indicates whether the system has this appearance, otherwise the default appearance is used.

EditText properties of "turn" Android development

Related Article

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.