TextInputLayout应用


源码解释:

   Layout which wraps an EditText (or descendant) to show a floating label when the hint is hidden due to the user inputting text. Also supports showing an error via setErrorEnabled(boolean) and setError(CharSequence)

    TextInputLayout 是EditText(或者EditText子类)的一个包装类,它主要用于在用户输入文本的时候显示一个浮动标签,也支持显示错误信息和字符计数等功能。同样它也支持密码可见切换按钮,通过setPasswordVisibilityToggleEnabled(boolean)API 或者 xml 中的属性,如果设置该属性为可用(enable),那么当EditText 显示设置的密码时,会显示一个切换密码可见和隐藏的按钮。


xml 如下:

   

  <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:passwordToggleEnabled="true"
        >

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"/>

    </android.support.design.widget.TextInputLayout>

 app:passwordToggleEnabled="true" 设置是否显示右边的


给EditText设置   android:hint="密码" 效果如图

给TextInputLayout设置属性
       //设置可以计数
        textInputLayout.setCounterEnabled(true);
        //计数的最大值
        textInputLayout.setCounterMaxLength(10);
效果如下




posted @ 2017-01-11 14:18  呼啦啦,,啦啦呼呼  阅读(167)  评论(0编辑  收藏  举报