Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the divider color of Spinner

Since my popup background is white in color I need to change the color of the spinner divider. I have tried styling the spinner in the following way but it does not work:

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>

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

Can I just combine all these into one?

like image 577
Veronika Gilbert Avatar asked Apr 15 '15 06:04

Veronika Gilbert


1 Answers

You need to put this theme in your manifest file like this:

<activity android:name="com.example.activity.Solution"
        android:theme="@style/applicationTheme">
</activity>
like image 94
Anjali Avatar answered Sep 21 '22 19:09

Anjali