Josh Earl
Josh Earl

Reputation: 18351

Applying custom styles to Android SpinnerItems

This question has been asked before, but carefully studying the answers on previous posts hasn't helped me decipher the problem.

I'm trying to apply custom styles to the items in a spinner control in my Android app, using a custom theme. I can't get the spinner items to respect the custom styles.

Here's what I have in themes.xml:

<resources>
  <style name="CustomTheme" parent="android:Theme">
    <item name="android:spinnerItemStyle">@style/CustomSpinnerItem</item>
    <item name="android:windowTitleSize">25dp</item> <!-- This works -->
  </style>
</resources>

And here's my styles.xml:

<resources>  
  <style name="CustomSpinnerItem" parent="android:Widget.TextView.SpinnerItem">
    <item name="android:textAppearance">@style/CustomTextAppearanceSpinnerItem</item>
    <item name="android:padding">20dp</item> <!-- This works fine -->
  </style>

  <style name="CustomTextAppearanceSpinnerItem" parent="android:TextAppearance.Widget.TextView.SpinnerItem">
    <item name="android:textColor">#F00</item> <!-- This does NOT work -->
  </style>
</resources>

Note the comments about what's working and what isn't. I'm pretty sure the problem is in the CustomTextAppearanceSpinnerItem section, but I'm at a loss as to what's wrong.

Any suggestions?

Upvotes: 2

Views: 1072

Answers (1)

sphairo
sphairo

Reputation: 11

This works well for me

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MySpinnerItem" parent="@android:Widget.TextView.SpinnerItem">
    <item name="android:textAppearance">@style/MySpinnerTextAppearance</item>
</style>
<style name="MySpinnerTextAppearance" parent="@android:TextAppearance.Widget.TextView.SpinnerItem">
    <item name="android:textColor">#FF0000</item>
</style>
</resources>

Upvotes: 1

Related Questions