我在布局中使用了材质轮廓化的texfield,我想将光标和指针的颜色更改为红色,但仅限于出现错误时。因此,基本上我希望我的光标始终与轮廓颜色匹配(聚焦时为原色,错误时为红色)。有人知道该怎么做吗?
我在我的应用程序和TextInputLayout中使用MaterialComponents主题,在使用@ style / Widget.MaterialComponents.TextInputLayout.OutlinedBox。一切都根据官方文档进行。
我知道我可以自定义主题并更改主题色,但我不知道如何在运行时更改主题(我只希望在出现错误时将其更改为红色)。
我也知道我可以设置自定义光标可绘制,但不会更改指针。我可能也可以设置自定义指针可绘制(?),但随后必须使其与默认指针一样漂亮,而且听起来很难。
显然,我不想将可绘制的光标设置为null并使它与文本颜色匹配。我的文字颜色是黑色,当聚焦时我的光标颜色应该是我的主要颜色,错误时应该是红色。
所以我有点想法不通了。
有人知道该怎么做吗?
在build.gradle中:
implementation 'com.google.android.material:material:1.1.0-alpha07'
样式:
<style name="Apptheme" parent="Theme.MaterialComponents.Light.NoactionBar"/>
在布局中:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/title_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:hintEnabled="true"
android:hint="Title">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/title_edittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />