我试着用这些台词来做些什么:

我可以使用android:hint="Email Address"显示提示,但不能显示辅助文本-这将是您的电子邮件用户名。
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="15"
android:hint="Username"
app:et_helper="Username is preferably your registered email"/>
</android.support.design.widget.TextInputLayout>`我得到的只是,没有用户名,最好是您的注册电子邮件,以下编辑:
输出:

任何指南针都会赏识。谢谢。
发布于 2015-11-24 10:56:06
最好的方法是使用TextInputLayout。谷歌把它引入了新的设计库。为了使用TextInputLayout,必须在build.gradle依赖项中添加以下内容:
compile 'com.android.support:design:22.2.0'然后在xml文件中使用它:
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your name"/>
</android.support.design.widget.TextInputLayout>您可以通过将错误设置为true来设置文本。虽然它是用来显示错误的,但它适合你使用。如果你愿意,你可以改变颜色和字体。
TextInputLayout til = (TextInputLayout) findViewById(R.id.textInputLayout);
til.setErrorEnabled(true);
til.setError("You need to enter a name");

发布于 2018-11-19 12:59:44
使用Design 28,在TextInputLayout中添加了内置的辅助文本功能。
implementation 'com.android.support:design:28.0.0'现在使用xml或以编程方式启用错误
textInputLayout.isHelperTextEnabled=true
textInputLayout.error="Email can not be Empty!!!"另外,提示和错误现在可以一起使用!
示例
et.setOnFocusChangeListener { v, b ->
if (b) {
textInputLayout.helperText = "yourhelperText"
} else {
textInputLayout.helperText = null
if(et.text.toString()==""){ // or any other validation
textInputLayout.error="Email can not be Empty!!!"
}
}编辑不要忘记通过或编程启用错误和helperText。
发布于 2021-01-11 10:14:38
具有TextInputLayout OutlinedBox样式和TextInputEditText的完整XML
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_customer_no"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:padding="3dp"
app:helperTextEnabled="true"
app:helperText="* Enter customer number that will be used">
<!--android:maxLength="13"-->
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_customer_no"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Customer No"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>https://stackoverflow.com/questions/33891482
复制相似问题