oferiko
oferiko

Reputation: 1957

Custom Spinner with white text color

I want my Action Bar spinner to display it's text in white (like in google maps app), but i'm struggling to get there..

i'm trying something like this:

   <style name="Mepo.Spinner" parent="@android:style/Widget.Spinner">
   <item name="android:spinnerItemStyle">@style/StandardSpinnerItem</item>  
   <item name="spinnerItemStyle">@style/StandardSpinnerItem</item>
   </style>

  <style name="StandardSpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem">
  <item name="android:textAppearance">@android:color/white</item>
  <item name="android:textColor">@android:color/white</item>
  </style>

but that has no effect. I know this his probably been asked but i can't find the right solution. any ideas? p.s i'm actually using sherlock action bar if that matters

Upvotes: 3

Views: 1965

Answers (2)

Ionut Negru
Ionut Negru

Reputation: 6314

If you already use an custom theme(you extended the base theme and customized it) and you want to customize the spinner only for one activity you need to do this:

<style name="Theme.MyTheme" parent="Theme.Sherlock">
... your other items
</style>

<style name="Theme.MyTheme.Spinner" parent="Theme.MyTheme">
    <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
    <item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item>
</style>

<style name="Spinner" parent="@android:style/Widget.Spinner">
    <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
    <item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item>
</style>    
<style name="SpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem">
    <item name="android:textColor">@android:color/white</item>
</style>
<style name="SpinnerItem.DropDownItem" parent="@android:style/Widget.Holo.Light.DropDownItem.Spinner">
    <item name="android:textColor">@android:color/white</item>
</style>

And to use this style in an activity use this:

<activity
    android:name=".YourActivity"
    android:theme="@style/Theme.MyTheme.Spinner"  >
</activity>

If you want to customize the spinner for all the activities(your application) move the items from Theme.MyTheme.Spinner into Theme.MyTheme:

<style name="Theme.MyTheme" parent="Theme.Sherlock">
   ... your other items
   <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
   <item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem</item>
</style>

Upvotes: 1

oferiko
oferiko

Reputation: 1957

in the end this is what i did, maybe this will help someone:

<style name="Theme.Styled" parent="Theme.Sherlock.Light.DarkActionBar">
        <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
        <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
        <item name="actionDropDownStyle">@style/xxx.ActionBar.DropDown.Style</item>
        <item name="android:actionDropDownStyle">@style/xxx.ActionBar.DropDown.Style</item>
    </style>
   <style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
        <item name="background">#0B2F39</item>
        <item name="android:background">#0B2F39</item>
        <item name="backgroundSplit">#0B2F39</item>
        <item name="android:backgroundSplit">#0B2F39</item>
    </style>

    <style name="xxx.ActionBar.DropDown.Style" parent="Widget.Sherlock.Light.Spinner.DropDown.ActionBar">
        <item name="android:background">@drawable/abs__spinner_ab_holo_dark</item>
    </style>

if you have any remark or corretions i would love to hear them

Upvotes: 1

Related Questions