效果图:
使用方法:
依赖:
compile 'com.android.support:design:22.2.0'
使用:
布局:
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayoutName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp">
<EditText
android:id="@+id/editTextName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入账号"
android:textColorHint="@color/colorGray"
/>
</android.support.design.widget.TextInputLayout>
代码中校验edittext:
if(TextUtils.isEmpty(text1)){
//红色提示语
textInputLayoutName.setError("账号不能为空!");
}else{
//这一步主要作用是消除edittext非空时下面的红色提示
textInputLayoutName.setError(null);
}