Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change holo spinner text colour

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.

like image 232
DaveSav Avatar asked May 19 '13 19:05

DaveSav


2 Answers

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.

  • themes.xml
  • styles.xml
like image 158
Woda Avatar answered Oct 23 '22 15:10

Woda


I fixed it by calling

mArrayAdapter.setDropDownViewTheme(mActivity.getTheme());

Hope this helps someone ;)

like image 44
Nobody Knows Avatar answered Oct 23 '22 17:10

Nobody Knows