根据 Google 的材料指南:
https://material.io/guidelines/components/text-fields.html#text-fields-layout https://material.io/guidelines/components/text-fields.html#text-fields-layout
TextInputLayout 提示应与错误消息的颜色相同:
然而事实并非如此,当我打电话时setError("My error")
只有下划线和错误消息显示为红色。
如何更改此行为以适应 Google 自己的准则?
您可以这样做:
<android.support.design.widget.TextInputLayout
android:padding="8dp"
android:id="@+id/tilSample"
app:errorTextAppearance="@style/error_appearance"
app:hintTextAppearance="@style/error_appearance"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/etSample"
android:layout_margin="8dp"
android:padding="8dp"
android:hint="android"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
样式.xml
<style name="error_appearance" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/colorRed</item>
<item name="android:textSize">12sp</item>
</style>
颜色.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorRed">#f44336</color>
</resources>
EDIT
我们还可以使用以下方法操纵代码中的错误和提示颜色:
tilSample.setErrorTextAppearance(R.style.error_appearance);
tilSample.setHintTextAppearance(R.style.error_appearance);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)