Android Honeycomb: 如何在ActionBar的Spinner中正确地样式化右侧箭头

8

这是一个相当具体的问题。我在onCreate()方法中添加了一个ActionBar上的Spinner。我已经成功将文本样式设置为白色,但无法让下划线和右下角的三角形/箭头也显示为白色。以下是我的样式:

<item name="android:actionDropDownStyle">@style/customActionBarDropDownStyle</item>

<style name="customActionBarDropDownStyle" parent="android:style/Widget.Holo.Light.Spinner">
    <item name="android:textColor">#FFFFFF</item>
</style>

我找不到一种样式元素/属性,可以使下划线和三角形变成白色。是否存在这样的元素?

以下是一个示例。我用红色突出显示了要使其变为白色的三角形和下划线。

enter image description here


不好意思,我还没有找到一种方法来实现这个。 - CACuzcatlan
3个回答

7
有点晚了,但总比没有好 :) 您应该创建一个新的9 patch drawable,并将其设置为android:actionDropDownStyle的背景。
以下是一个示例:
    <item name="android:actionDropDownStyle">@style/customActionBarDropDownStyle</item>
    <style name="customActionBarDropDownStyle"parent="android:style/Widget.Holo.Light.Spinner">
    <item name="android:background">@drawable/custom_spinner_dropdown</item>
    </style>

由于大多数原生组件的背景都是9-patch pngs,因此你无法为几乎每个原生组件设置颜色。


1

actionDropDownStyle无法用于更改您在操作栏上添加的微调器的样式;它适用于其中一个操作栏模式ActionBar.NAVIGATION_MODE_LIST;

至于您的问题,您可以在布局文件中为微调器定义一个选择器,就像这样:

enter code here
<Spinner
    android:dropDownWidth="200dp"
    android:background="@drawable/actionbar_spinner"
    android:id="@+id/action_spinner"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_marginRight="10dp" />
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false"
        android:drawable="@drawable/spinner_ab_disabled" />
    <item android:state_pressed="true"
        android:drawable="@drawable/spinner_ab_pressed" />
    <item android:state_pressed="false" android:state_focused="true"
        android:drawable="@drawable/spinner_ab_focused" />
    <item android:drawable="@drawable/spinner_ab_default" />
</selector>

0
尝试这个:android:background="@null"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接