Android Control--edittext

Source: Internet
Author: User

XML attributes for EditText and methods in classes

XML properties Methods in class Description
Android:text SetText (charsequence text) Set text content
Android:textcolor SetTextColor (int color) Font Color
Android:hint Sethint () Text displayed when content is empty
Android:textcolorhint Sethinttextcolor (int color) Color of display text when content is empty

Android:inputtype

Setinputtype (int type)

restricting input types

Number: integer type

Numberdecimal: Floating-point type

Date: Day type

Text: literal type (default)

Phone: dial pad

Textpassword: Password

Textvisiblepassword: Visible Password

Numberpassword: Digital Password

Texturi: URL

Android:maxlength Limit the length of text that is displayed, which is not displayed or does not exist
Android:minlines Sets the minimum number of lines of text.
Android:maxlines Sets the maximum number of lines of text. The text goes up and scrolls upwards.
Android:gravity Setgravity () Sets the position of the text.
Android:drawableleft Output a drawable, slice on the left side of the Exittext text.
Android:drawablepadding Sets the interval between text and drawable in Exittext. Can be set to negative numbers, used alone without effect, must be used in conjunction with Android:drawableleft and so on.

Android:ellipsize

Sets how the control is displayed when the text is too long.

Strat: ellipses appear at the beginning.

End: ellipses appear at the end.

Middle: ellipses appear at the end.

Marquee: Display in the way of a marquee (animated lateral movement)

Note: Exittext only have effect on suggestive text, marquee has no effect in exittext.

TextView effect in a

Android:lines Setlines () Set the number of lines of text, set two lines to display two lines, that is, the second row has no data
Android:linespacingextra Set line spacing
Android:singleline Setsingleline () True: Single-line display. False: Multiple lines are displayed.
Android:textstyle To set a glyph, you can set multiple values, separated by \

Common Login interface in EditText

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical">    <EditTextAndroid:id= "@+id/et_phone"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_marginleft= "20DP"Android:layout_marginright= "20DP"Android:background= "@null"Android:inputtype= "Number"Android:maxlength= "One"Android:hint= "Please enter phone number"android:drawablepadding= "10DP"android:padding= "10DP"Android:drawableleft= "@mipmap/icon_phone"Android:drawablebottom= "@drawable/shape_et_bottom_line"Android:layout_margintop= "20DP"/>    <EditTextAndroid:id= "@+id/et_password"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_marginleft= "20DP"Android:layout_marginright= "20DP"Android:layout_margintop= "10DP"Android:background= "@null"Android:inputtype= "Textpassword"Android:maxlength= "+"android:padding= "10DP"android:drawablepadding= "10DP"Android:hint= "Please enter password"Android:drawablebottom= "@drawable/shape_et_bottom_line"Android:drawableleft= "@mipmap/icon_password"/>    <TextViewAndroid:id= "@+id/tv_login"style= "@style/widget.appcompat.button.colored"Android:layout_width= "Match_parent"Android:layout_height= "50DP"Android:layout_marginleft= "10DP"Android:layout_marginright= "10DP"Android:layout_margintop= "30DP"Android:text= "Login"Android:textcolor= "#ffffffff"android:textsize= "18SP" /></LinearLayout>

Operation Result:

Most of the properties used in these two input boxes are in the table above, and I'll address the properties that are not mentioned here.
Android:background= "@null" input box no background
Android:drawablebottom= "@drawable/shape_et_bottom_line" The bottom of the introduction of a shape layout file, this layout file is the input box underline.
Shape_et_bottom_line.xml content is as follows:

<Shapexmlns:android= "Http://schemas.android.com/apk/res/android"Android:shape= "Rectangle" >    <SolidAndroid:color= "#1E7EE3" />    <sizeAndroid:height= "1DP"Android:width= "500DP"/></Shape>
What other features do editetext have?

1. Listen for user input content.
There is a scene, a search box, as long as the user input content to request the server, so we listen to activity inside editetext text change events.

EditText etone=(EditText) Findviewbyid (R.id.et_phone); Etone.addtextchangedlistener (NewTextwatcher () {@Override Public voidBeforetextchanged (Charsequence S,intStartintCountintAfter ) {LOG.I ("Ansen", "Call before content changes:" +s); } @Override Public voidOnTextChanged (Charsequence S,intStartintBefore,intcount) {LOG.I ("Ansen", "content changes, can go to tell the server:" +s); } @Override Public voidaftertextchanged (Editable s) {log.i ("Ansen", "Call after content change:" +s); } });

First we find the EditText control through the ID, and add the listener function, implement the Textwatcher interface inside, rewrite three methods. We can tell the server what I want to search in the OnTextChanged method.

Source Download

Login Source

Original


Finish.

Android Control--edittext

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.