更改微调器三角形背景颜色

Change Spinner Triangle background color

我想制作三角形背景颜色为蓝色的微调器。但是微调器的基本颜色仍然和以前一样。

我只找到了改变三角形颜色或微调器基本颜色的解决方案。

See this

试试这个:

First Way (Simpler):

在您的 xml 中,确保您的微调器有一个 ID。在这个例子中,让我们调用 id "spinner".

在您的代码中,在您的 onCreate() 中添加以下内容:

Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.getBackground().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP);

其中红色是您在值文件夹中的 colors.xml 中定义的颜色。

Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.getBackground().setColorFilter(Color.parseColor("#AA7744"), PorterDuff.Mode.SRC_ATOP);

Second Way:

您可以使用这个在线工具:http://android-holo-colors.com

真的很棒。它将使用您喜欢的颜色为您生成自定义可绘制对象。确保将主题选择为 holo(或任何其他你想要的)和 select spinner。

Third Way:

您应该创建一个新的 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 png。

对于API 21+来说变得简单多了:

 <Spinner
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:backgroundTint="@color/white" />