Simple use of textinputlayout and Floatingactionbutton under the Android design package

Source: Internet
Author: User

Finally introduced to the design package of the last thing.

Also very simple, one is textinputlayout.

Textinputlayout as a parent container, contains a new edittext, can add unexpected effects to edittext, especially in the registration function development, the use is very extensive.

It can directly prompt for input errors, and not always click the button as before to detect the input errors, when there are many output boxes are difficult to distinguish.

You can also put the hint default prompt value on the top.

The implementation interface is probably the case.

This is true when you enter it correctly.

The implementation code is also simple.

Add a listener Focus event

  @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_text_input);        TextInput = (textinputlayout) Findviewbyid (r.id.text_input_layout);        Textinput.getedittext (). Addtextchangedlistener (this);    }    @Override public    void beforetextchanged (Charsequence s, int. start, int count, int after) {    }    @Override Public    void OnTextChanged (charsequence s, int start, int before, int count) {    }    //completion    @Override Public    void aftertextchanged (Editable s) {        if (s.length () <6) {            textinput.seterror ("Password cannot be less than 6! ");            Textinput.seterrorenabled (True);        } else{            textinput.seterrorenabled (false);        }    }

  

Definitions in the XML file

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "xmlns:tools=" Http://schemas.android.com/tools "android:layout_width=" Match_parent "android:layout_height = "Match_parent" android:orientation= "vertical" tools:context= "         Com.example.nanchen.designcoodinatordemo.TextInputActivity "> <edittext android:layout_width=" match_parent "        android:hint= "Enter user name ..." android:layout_height= "Wrap_content"/> <android.support.design.widget.textinputlayout android:layout_w Idth= "Match_parent" android:id= "@+id/text_input_layout" android:layout_height= "Wrap_content" > < EditText android:layout_width= "match_parent" android:hint= "Enter password ..." android:layout_height = "Wrap_content"/> </android.support.design.widget.TextInputLayout> < Android.support.design.widget.TextInputEditText android:layout_width= "Match_pArent "android:layout_height=" Wrap_content "android:hint=" Mailbox "/></linearlayout> 

  

And then look at Floatingactionbutton.

In fact, it is a can hover button, you can put it in the Coordinatorlayout container and rewrite Floatingactionbutton behavior can achieve the desired effect.

Here is the drop-down hidden.

Package Com.example.nanchen.designcoodinatordemo;import Android.content.context;import Android.support.design.widget.coordinatorlayout;import Android.support.design.widget.FloatingActionButton; Import Android.util.attributeset;import android.view.view;/** * Custom behavior * Created by Southern dust on 16-7-14. */public class Mybehavior extends Floatingactionbutton.behavior {//write this constructor method to specify public Mybehavior directly in the XML file (Context    Context, AttributeSet Attrs) {super ();  } @Override public boolean onstartnestedscroll (Coordinatorlayout coordinatorlayout, Floatingactionbutton Child, View Directtargetchild, View target, int nestedscrollaxes) {return true;//return true means we care about this scrolling event} @Override Publ IC void Onnestedprescroll (Coordinatorlayout coordinatorlayout, Floatingactionbutton Child, View target, int dx, int dy, in        T[] consumed) {Super.onnestedprescroll (coordinatorlayout, child, target, DX, dy, consumed); if (Dy < 0) {//Scroll down//viewcompat.animate (CHILD). ScaleX (1). Alpha (1). Start ();        Child.show ();            } else {//scroll up//viewcompat.animate (Child). ScaleX (0). Alpha (0). Start ();        Child.hide (); }    }}

Floatingactionbutton is shown and hidden by show and hide methods.

The specific picture is not cut, I do not come gif motion diagram, slightly embarrassed, but the time must be good learning!

Simple use of textinputlayout and Floatingactionbutton under the Android design package

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.