android 新控件风格,Android中Material Design风格控件的应用(一)

TextInputLayout

效果

以后有空再放吧

一、导入Support Library

Material Design控件是Android Support Library中的一个重要的组件,要使用TextInputLayout控件,你需要导入两个Library。第一个是appcompat-v7,它确保material style可以向后兼容。第二个是Design Support Library。在你的build.gradle文件中,添加如下依赖:

compile 'com.android.support:design:25.2.0'

compile 'com.android.support:appcompat-v7:25.2.0'

二、在XML中使用该控件

TextInputEditText的使用必须在TextInputLayout中才有这种MD的效果

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:maxLines="1"

android:id="@+id/edit_mobile"

android:layout_width="match_parent"

android:layout_height="48dp"

android:layout_marginLeft="8dp"

android:hint="手机号"

android:inputType="number"/>

其实这里跟EditText没有多大的区别

三、在代码中实现显示错误信息的功能

/**

* 用于TextInputEditText控件显示错误信息

* @param textInputEditText 控件对象

* @param error 错误信息

*/

private void showError(TextInputEditText textInputEditText, String error) {

textInputEditText.setError(error);

textInputEditText.setFocusable(true);

textInputEditText.setFocusableInTouchMode(true);

textInputEditText.requestFocus();

}

不解释了好吧,在检验到错误的时候调用就好了。

以上

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值