android - 更改微调器箭头,Appcompat v21

标签 android spinner styling android-appcompat

我的 Activity 以我的自定义主题为主题,但对于微调器,我选择使用 Appcompat v21 对其进行样式设置,但我得到了这个: enter image description here

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

我发现这是一个类似的问题,但没有任何答案: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>

然后在使用微调器的 XML 中添加这一行

android:theme="@style/customSpinnerTheme"

例如

<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" />

关于android - 更改微调器箭头,Appcompat v21,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30135258/

相关文章:

android - 如何从 android 的 ListView 中删除分隔符?

android - 如何在 gradle 中获取当前 flavor

java - Android 应用程序因 NPE 崩溃

c# - 当文本框的背景在 wpf 中为灰色时插入符消失

SVG <use> 忽略渐变样式

android - New Relic 无法使用 eclipse 正确加载(Android)

java - 使用 InAppBrowser 和微调器加载页面后无法输入输入字段

java - 如何在 Android 中使用已保存的实例状态和通过微调器恢复实例状态?

android - 如何在 Spinner Android 中添加项目

android - 具有可绘制背景和可绘制左侧的样式按钮