Change holo spinner text colour

12,317

Solution 1

Have you tried to accept the SpinnerItemStyle to your Theme? So all Spinners in your App would've the same style. I'm using it like this and it works:

theme.xml:

<style name="exampleTheme" parent="android:Theme.Holo.Light">
    <item name="android:spinnerItemStyle">@style/SpinnerItem_example</item>
    ...
</style>

style.xml:

<style name="SpinnerItem_example" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
        <item name="android:textColor">#000000</item>
</style>

Update: Taking a deeper look into the styles.xml brought me this:

<style name="Widget.DropDownItem.Spinner">
        <item name="android:checkMark">?android:attr/listChoiceIndicatorSingle</item>
</style>

<style name="Widget.DropDownItem">
        <item name="android:textAppearance">@style/TextAppearance.Widget.DropDownItem</item>
        <item name="android:paddingStart">@dimen/dropdownitem_text_padding_left</item>
        <item name="android:paddingEnd">@dimen/dropdownitem_text_padding_right</item>
        <item name="android:gravity">center_vertical</item>
</style>

So you probably need to customize the Widget.DropDownItem and accept it in your theme.

...
<item name="dropDownItemStyle">@android:style/Widget.DropDownItem</item>
...

For customizing my application the following two links helped me a lot to understand the structure of the different views. These two files are part of the android source code. May be it helps you too.

Solution 2

I fixed it by calling

mArrayAdapter.setDropDownViewTheme(mActivity.getTheme());

Hope this helps someone ;)

Share:
12,317
DaveSav
Author by

DaveSav

I have a passion for creating things that really help people and to this end I run a non-profit organisation developing health apps for people with chronic conditions.

Updated on June 14, 2022

Comments

  • DaveSav
    DaveSav about 2 years

    I have a spinner in a Holo theme dialog and am trying to change the text colour because it is very hard to read:

    dialog spinner text colour

    I have looked at android styles.xml, as well as many other answers, and believe that I am setting the custom style correctly; but it's just not getting picked up.

    This is an extract from the dialog layout file where the spinner lives:

    <Spinner
            android:id="@+id/spn_Type"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:entries="@array/dose_type_options"
            style="@style/DialogSpinner" />
    

    And these are the relevant entries in styles.xml in the values-v14 folder:

    <style name="DialogSpinner" parent="@android:style/Widget.Holo.Spinner">
            <item name="android:spinnerItemStyle">@style/MySpinnerItem</item>
    </style>
    
    <style name="MySpinnerItem" parent="android:Widget.Holo.TextView.SpinnerItem">
        <item name="android:textAppearance">@style/MyTextAppearanceSpinnerItem</item>
    </style>
    
    <style name="MyTextAppearanceSpinnerItem" parent="android:TextAppearance.Holo.Widget.TextView.SpinnerItem">
        <item name="android:textColor">#FFF</item>
    </style>
    

    The dialog itself is forced to the Holo dark theme by using:

    <style name="FibroDialog" parent="@android:style/Theme.Holo.Dialog">
    
    </style>
    

    Can anyone identify why the spinner text isn't white?

    I have looked at other solutions, which suggest changing the colour in code, but this app supports 2.3.* upwards, so for those non-holo versions black text is fine, hence trying to do it by styles.

    Thanks

    Updated using answer from Woda below

    The text colour of the initial value of the spinner is now white, which goes a long way to highlighting that there is a spinner there for the user:

    dialog spinner text colour 2

    But the text colour of the selectable items is still black. I guess it's not a massive deal, at least the existence of the spinner has been affirmed by getting the initial text changed to white. But I would be interested to know why the items are still black, and how to change them to white.

  • DaveSav
    DaveSav about 11 years
    Thanks, Woda. That's done enough for me for now. See my updates above for what happened.
  • Woda
    Woda about 11 years
    I updated my answer above. Unfortunatley I don't have the time to check exactly solves your problem.
  • DaveSav
    DaveSav about 11 years
    No, that didn't seem to work. But thanks for the initial answer.
  • Sajitha Rathnayake
    Sajitha Rathnayake over 10 years
    I'm new to Android, so i need to know Where to put theme.xml and style.xml files? and how to apply them??