更改Spinner的分隔符颜色

6

由于我的弹出窗口背景是白色的,所以我需要更改旋转器分隔符的颜色。我已经尝试以以下方式对旋转器进行样式设置,但它不起作用:

styles.xml

<style name="applicationTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:dropDownListViewStyle">@style/SpinnerStyle</item>
</style>

<style name="SpinnerStyle" parent="android:Widget.ListView.DropDown">
    <item name="android:divider">#0193DE</item>
    <item name="android:dividerHeight">1dp</item>
</style>
(主xml)
<Spinner
        android:id="@+id/year"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:background="@drawable/apptheme_spinner_default_holo_dark"
        android:layout_marginLeft="75dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="10dp"
        android:spinnerMode="dropdown"
        style="@style/SpinnerStyle" 
        android:popupBackground="#FFFFFF" />

java

ArrayAdapter<Integer> adapter_year = new ArrayAdapter<Integer>(this, R.drawable.custom_spinner_holidays, year);
    adapter_year.setDropDownViewResource(R.layout.custom_spinner_popup);

custom_spinner_holidays.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:textColor="@android:color/white" />

自定义旋转弹出窗口

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee"
    android:singleLine="true"
    android:textColor="#0193DE" />

我能把所有这些内容合并成一个吗?

我仍在等待一个完美的答案.. 似乎没有任何东西能够工作 :( - Veronika Gilbert
有谁可以帮助我吗?我卡在这里了! - Veronika Gilbert
2个回答

2
您需要像这样将此主题放入清单文件中:

您需要在清单文件中加入如下代码:

<activity android:name="com.example.activity.Solution"
        android:theme="@style/applicationTheme">
</activity>

0
也许最好的想法是自己做一个Spinner,并以你想要的方式进行样式设计。看一下下一个主题,它对我非常有用。

如何在Android中自定义Spinner


我的实际问题是样式没有应用到微调器上。没有运行时错误。为什么会这样发生? - Veronika Gilbert
也许您忘记在活动中设置样式了?https://dev59.com/tm455IYBdhLWcg3wD_oB#10177016 - acostela

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