更改旋转箭头,Appcompat v21

2024-04-14

i have activities which i themed with my custom theme, but for spinner i choosed to style it with Appcompat v21 but i got this : enter image description here

那么如果有办法的话,如何将 Spinner 箭头更改为黑色或蓝色呢?

我发现这是类似的问题,但没有任何答案:https://stackoverflow.com/questions/28561105/add-custom-spinner-arrow https://stackoverflow.com/questions/28561105/add-custom-spinner-arrow这是我的微调器:

<Spinner
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/spinner2"
        android:layout_marginTop="10dp"
        android:layout_centerInParent="true" />

我用它来设计微调器的样式:

 <style name="MyTheme.SpinnerAppTheme" parent="Widget.AppCompat.Spinner">
    </style>

这就是我使用适配器的方式

   ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                getBaseContext(), R.array.listMedRes, android.R.layout.simple_spinner_item);

我只想为微调器设置主题,非常感谢


可能会迟到,但迟到总比不到好。回答你的问题:“有没有办法只在微调器中使用它?”。答案是肯定的,参考下面的代码。

将此代码添加到您的主题或样式文件中

<style name="customSpinnerTheme" parent="yourAppThemeThatUseAppCompat21">
    <item name="colorControlNormal">#eaeaea</item>
    <item name="colorControlActivated">#000000</item>
    <item name="colorControlHighlight">#000000</item>
</style>

然后在使用 spinner 的 XML 中,您可以添加这一行

android:theme="@style/customSpinnerTheme"

e.g.

<Spinner
    android:theme="@style/customSpinnerTheme"
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:spinnerMode="dialog" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

更改旋转箭头,Appcompat v21 的相关文章

随机推荐