Android 微调器下划线颜色
Android Spinner Underline color
我可以使用 style="@style/Base.Widget.AppCompat.Spinner.Underlined"
在微调器中添加下划线。如何仅使用样式更改下划线的颜色?我不想使用任何可绘制文件来更改它。
<item name="colorControlHighlight">@color/colorAccent</item>
<item name="colorControlNormal">@color/colorAccent</item>
使用上面的样式,它只在用户点击时突出显示下划线。它在正常状态下不会改变下划线的颜色。
默认情况下,Spinner
将使用通过 android:textColorSecondary
或 colorControlNormal
在您的 AppTheme
中设置的颜色。因此,要么在那里设置适当的颜色,要么定义一个新的主题并将其应用于您的 Spinner:
示例:
styles.xml
<style name="ThemeSpinner">
<!-- Color when pressed -->
<item name="colorAccent">#ffa000</item>
<!-- Default color for the dropdown arrow and line -->
<item name="colorControlNormal">#ffc107</item>
</style>
layout.xml
<Spinner
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeSpinner" />
注意: 下拉箭头也会有颜色 - 我不知道有颜色选项箭头分开
这个问题好像已经有人回答了。但这里也有一种以编程方式解决该问题的方法。 (在 API 19 及以上测试)。
为此使用 ViewCompat
。
ViewCompat.setBackgroundTintList(spinner, ColorStateList.valueOf(your_color));
将此添加到微调器
android:backgroundTint="@color/gray"
我可以使用 style="@style/Base.Widget.AppCompat.Spinner.Underlined"
在微调器中添加下划线。如何仅使用样式更改下划线的颜色?我不想使用任何可绘制文件来更改它。
<item name="colorControlHighlight">@color/colorAccent</item>
<item name="colorControlNormal">@color/colorAccent</item>
使用上面的样式,它只在用户点击时突出显示下划线。它在正常状态下不会改变下划线的颜色。
默认情况下,Spinner
将使用通过 android:textColorSecondary
或 colorControlNormal
在您的 AppTheme
中设置的颜色。因此,要么在那里设置适当的颜色,要么定义一个新的主题并将其应用于您的 Spinner:
示例:
styles.xml
<style name="ThemeSpinner">
<!-- Color when pressed -->
<item name="colorAccent">#ffa000</item>
<!-- Default color for the dropdown arrow and line -->
<item name="colorControlNormal">#ffc107</item>
</style>
layout.xml
<Spinner
style="@style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeSpinner" />
注意: 下拉箭头也会有颜色 - 我不知道有颜色选项箭头分开
这个问题好像已经有人回答了。但这里也有一种以编程方式解决该问题的方法。 (在 API 19 及以上测试)。
为此使用 ViewCompat
。
ViewCompat.setBackgroundTintList(spinner, ColorStateList.valueOf(your_color));
将此添加到微调器
android:backgroundTint="@color/gray"