Material Design Textinputlayout Use example

Source: Internet
Author: User

Using Textinputlayout to create a login interface

1. Import the support Library

Using the Textinputlayout control requires importing two libraries, one is appcompat-v7, ensuring material styles can be backwards compatible. The other is the design support Library.  

In the project's Build.gradle file, add the following dependencies (dependencies):

dependencies {        compile filetree (dir: ' Libs ', include: ['*. Jar '])        compile ' com.android.support: Design:22.2.0'        compile ' com.android.support:appcompat-v7:22.2.0'    }

2. Using Textinputlayout

The Textinputlayout control behaves just like LinearLayout, which is a container. Only one child element can be placed in the textinputlayout, and the ScrollView is somewhat similar, and the child element must be edittext.

<android. support.design.widget.TextInputLayout    android:id= "@+id/usernamewrapper"     Android:layout_width= "Match_parent"    android:layout_height= "Wrap_content" >    < EditText android:id= "@+id/username"        android:layout_width= "Match_parent"        android:layout_ Height= "wrap_content"        android:inputtype= "textemailaddress"        android:hint= "Username"/></android .support.design.widget.textinputlayout>

Did you notice that I set an attribute-hint in EditText. This property is very familiar to everyone, EditText did not enter the time, hint will show, when the first letter entered the time, hint disappeared. The experience is not so good.
Thanks to Textinputlayout, this is not a problem right now. When you enter the first letter in the EditText to hide the hint, a floating label appears in Textinputlayout to show the hint and is responsible for a cool material animation.

Note: edittext height can be fixed, textinputlayout height is not fixed, otherwise textinputlayout SetError () information may not display properly

3.App:hinttextappearance= "@style/floatingstyle"

app:hinttextappearance= "@style/floatingstyle" is used to set the style of the floating font.

<style name= "Floatingstyle" parent= "@android: Style/textappearance" >        <item name= "Android:textcolor" > #e0ffffff </item>        <item name= "android:textsize" >12sp</item>  </style>

Textinputlayout can use the SetError () method to display an error message below the input box, using a edittext-like SetError (). Similarly, you can use App:errortextappearance to set the font style for error messages in XML.

Reference Link: http://www.mamicode.com/info-detail-965904.html

Other Links: http://www.open-open.com/lib/view/open1433496206666.html

Material Design Textinputlayout Use example

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.