Android里设置EditText控件的提示信息的方法

发表于 2020-12-21 16:38:13
阅读 84

介绍

介绍

福哥想在Android里实现类似placeholder的效果,找了半天没找到。后来查了一下资料,发现了这个等效的属性——hint,使用hint可以实现类似HTML里面的placeholder的效果。

这种效果会很节约空间,用户体验好很多。

设置提示信息

通过hint设置输入框的提示信息。

<EditText
    android:id="@+id/txt"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_marginBottom="30dp"
    android:cursorVisible="true"
    android:background="#ffffff"
    android:textCursorDrawable="@null"
    android:singleLine="true"
    android:hint="账号(由字符和数字组成,且第一个字符必须为字母)"/>

总结

今天福哥教给童鞋们学会了使用hint属性给输入框增加提示信息。