Android Spinner下划线颜色 [英] Android Spinner Underline color

查看:576
本文介绍了Android Spinner下划线颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用style="@style/Base.Widget.AppCompat.Spinner.Underlined"在微调器中添加下划线.如何仅使用样式更改下划线的颜色?我不想使用任何可绘制的文件来更改此设置.

I can add underline in spinner using style="@style/Base.Widget.AppCompat.Spinner.Underlined". How can I change color of underline using style only? I dont want to use any drawable file to change this.

 <item name="colorControlHighlight">@color/colorAccent</item>
 <item name="colorControlNormal">@color/colorAccent</item>

使用上述样式,当用户单击它时,它仅高亮显示下划线.正常状态下其下划线的颜色不变.

Using above style, Its only highlight underline when user click on it. Its not changing color of underline on normal state.

推荐答案

默认情况下,Spinner将使用AppTheme中通过android:textColorSecondarycolorControlNormal设置的颜色.因此,您可以在此处设置适当的颜色或定义一个新的主题,然后将其应用到您的微调框:

By default the Spinner will use the color set via android:textColorSecondary or colorControlNormal in your AppTheme. So either set the appropriate colors there or define a new Theme and apply this one to your 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" />

注意: 下拉箭头也会被着色-我不知道可以单独为箭头着色的选项

这篇关于Android Spinner下划线颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆