你可以通过在 styles.xml 中定义自定义样式来自定义 TextInputLayout 及其嵌入式 EditText 的外观。定义的样式可以作为样式或主题添加到 TextInputLayout。
自定义提示外观的示例:
styles.xml:
@color/black
@color/indigo
@color/pink
要应用样式,请按如下方式更新 TextInputLayout 和 EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/MyHintStyle">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/Title"
android:theme="@style/MyEditText" />
自定义 TextInputLayout 的强调色的示例。重音颜色会影响 EditText 的基线颜色和浮动提示文本的文本颜色:
styles.xml:
@color/primary
布局文件:
android:id="@+id/textInputLayout_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/TextInputLayoutWithPrimaryColor">
android:id="@+id/textInputEditText_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_hint_password"
android:inputType="textPassword" />