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

查看:42
本文介绍了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 将使用通过 android:textColorSecondarycolorControlNormal<设置的颜色/code> 在您的 AppTheme 中.因此,要么在那里设置适当的颜色,要么定义一个新主题并将其应用到您的微调器:

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天全站免登陆