问题描述
我正在尝试将Material Design的hintTextColor
的{{1}} AND 设置为BoxstrokeColor
三种颜色,例如:
- 蓝色为
disabled
但为enabled
- 绿色表示何时
unfocused
和enabled
我该怎么做?
对于focused
,我尝试了Gabriele Mariotti在here中提出的建议,但是问题是颜色之一应用于两种不同的状态([{{1 }}]和[hintTextColor
,但disabled
]),我想区分这两个。
解决方法
您可以使用自定义样式:
<style name="CustomOutlineBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="boxStrokeColor">@color/text_input_layout_stroke_color</item>
<item name="android:textColorHint">@color/text_color_hint</item>
<item name="hintTextColor">@color/green</item>
</style>
使用@color/text_color_hint
选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="..." android:color="@color/red" android:state_enabled="false"/>
<item android:alpha="..." android:color="@color/blue"/>
</selector>
和@color/text_input_layout_stroke_color
选择器:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:alpha="..." android:color="@color/green" android:state_focused="true"/>
<item android:alpha="..." android:color="@color/green" android:state_hovered="true"/>
<item android:alpha="..." android:color="@color/red" android:state_enabled="false"/>
<item android:alpha="..." android:color="@color/blue"/> <!-- unfocused -->
</selector>
重点:
不专心:
已禁用: