更改Spinner的分隔颜色

时间:2015-04-15 06:16:17

标签: android android-spinner

由于我的弹出背景为白色,我需要更改微调器分隔符的颜色。我尝试用以下方式设置微调器的样式,但它不起作用:

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

custom_spinner_popup

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

我可以将所有这些合并为一个吗?

2 个答案:

答案 0 :(得分:2)

您需要将此主题放在清单文件中,如下所示:

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

答案 1 :(得分:0)

也许最好的想法是做自己的微调器,你可以按照你想要的方式设计它。看看它对我来说非常有用的下一个主题。

How to customize a Spinner in Android

相关问题