Code Vader
Code Vader

Reputation: 755

Styling a Spinner on the ActionBar

I'm busy styling the theme of my app (blue/black with orange edges). I succesfully managed the actionbar, but I'm having trouble with a spinner/dropdown in the actionbar. Can anyone please suggest what I have to do to make the text color inside the spinner orange as well. Not the actual spinner items, just the one displayed at the top, i.e. the selected item.

At the moment it looks like this: enter image description here

And the style I'm using for the spinner looks like this:

<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme for API 11+. This theme completely replaces
        AppBaseTheme from res/values/styles.xml on API 11+ devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!-- API 11 theme customizations can go here. -->
    </style>

    <!-- SQUASHBOT THEME -->
    <style name="SquashBotTheme" parent="Theme.AppCompat.Light.DarkActionBar">

        <item name="android:actionBarStyle">@style/SquashBotTheme.ActionBarTheme</item>

        <item name="android:actionDropDownStyle">@style/SquashBotTheme.DropDownNavigation</item>

    </style>

        <!-- ACTIONBAR THEME -->
    <style name="SquashBotTheme.ActionBarTheme" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@drawable/actionbar_theme</item>
        <item name="android:titleTextStyle">@style/SquashBotTheme.TitleText</item>
    </style>

   <!-- TITLE TEXT --> 
   <style name="SquashBotTheme.TitleText" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:textColor">@color/OrangeRed</item>
    </style>

   <!-- DROPDOWN ITEM -->
   <style name="SquashBotTheme.DropDownNavigation" parent="@android:style/Widget.Holo.Spinner">
        <item name = "android:textAppearance">@color/OrangeRed</item>
        <item name = "android:textColor">@color/OrangeRed</item>
       <item name = "android:popupBackground">@color/OrangeRed</item>
   </style>

</resources>

As you can see, I've allready tried with textAppearance and textColor. Any suggestions would be much appreciated.

Upvotes: 0

Views: 733

Answers (1)

Andy
Andy

Reputation: 953

You can try this one:

spinner_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/YourStyleIsHere"
android:background="@color/white"
android:layout_width="match_parent"
android:singleLine="true"
android:drawableRight="@drawable/ic_action_dropdawn2"
android:ellipsize="end" />

dropdown_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/YourAnotherStyle"
android:layout_width="match_parent"
android:background="@drawable/phone_ripple"
android:padding="20dp"
android:ellipsize="end" />

Adapter

adapter = new YourAdapter(context, R.layout.spinner_item, models);
adapter.setDropDownViewResource(R.layout.dropdown_item);

Styles have parent @android:style/TextAppearance"

Upvotes: 2

Related Questions