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