6

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?

Veronika Gilbert
  • 471
  • 2
  • 8
  • 16

2 Answers2

2

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

<activity android:name="com.example.activity.Solution"
        android:theme="@style/applicationTheme">
</activity>
Anjali
  • 598
  • 2
  • 5
  • 15
0

Maybe the best idea it's doing your own spinner and you can style it in the way that you want. Take a look in the next thread it was so useful for me.

How to customize a Spinner in Android

Community
  • 1
  • 1
acostela
  • 2,597
  • 3
  • 33
  • 50
  • My actual problem is that the style is not getting applied on the spinner. There are no runtime errors. Why is that happening? – Veronika Gilbert Apr 15 '15 at 06:28
  • Maybe you forgot setting your style in your activity? http://stackoverflow.com/questions/4569751/how-to-show-divider-between-spinner-items/10177016#10177016 – acostela Apr 15 '15 at 07:09