1.TextInputLayout(2017/2/21)

TextInputLayout是MD中的一种登录界面,它有一个特点类似ScrollView就是它的内部只能有一个控件,而这个控件只能是EditText。接下来说下它的用法:

首先添加依赖

compile 'com.android.support:appcompat-v7:25.0.1'  //兼容低版本的浮动动画
compile 'com.android.support:design:25.0.1'              //引入design库

xml中布局代码




    
        
    

    
        
    

    

1.TextInputLayout(2017/2/21)_第1张图片
Paste_Image.png

几点注意事项

  • 取消EditText的默认获取焦点
    EditText默认是获取焦点的,这导致刚进入此页面,用户名就会上浮,并且键盘也默认被拉出。怎样改变这种默认设置,当我们点击时才出现上述的状态呢?就是在EditText的父控件加两行代码。
android:focusable="false"      //不能获取焦点
android:focusableInTouchMode="true"     //当触摸时才获取焦点
  • 更改EditText的hint默认颜色
    在TextInputLayout中通过下面这个属性
android:textColorHint="#5D4037"
  • 更改EditText的下滑线颜色
    EditText下滑线有默认的颜色,当获取焦点后又会有另一种默认的颜色,怎样自定义两种状态下的颜色,需要我们自己写一个style,然后通过EditText的theme属性引用这个style。
    
  • 怎样更改hint浮上去后的颜色?
    
1.TextInputLayout(2017/2/21)_第2张图片
Paste_Image.png
  • 如果账户是手机号,可以加入字符计数,在TextInputLayout中加入
app:counterEnabled="true"    //是否计数
app:counterMaxLength="11"   //最大长度
  • 密码时加入眼睛的图标,在TextInputLayout中加入
app:passwordToggleEnabled="true"

如果想自定义图标

app:passwordToggleDrawable="@drawable/bg"
1.TextInputLayout(2017/2/21)_第3张图片
Paste_Image.png

你可能感兴趣的:(1.TextInputLayout(2017/2/21))