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



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

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

请参阅此

试试这个:

第一种方式(更简单):

在xml中,确保您的微调器有一个id。在本例中,让我们将id称为"微调器"。

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

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

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

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

第二种方式:

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

真的很棒。它将为您生成具有您喜欢的颜色的自定义绘图。确保您选择主题为holo(或任何其他您想要的)并选择微调器。

第三种方式:

你应该创建一个新的9补丁可绘制,并将其设置为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。

API 21+:变得更简单

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

最新更新