Search code examples
androidandroid-theme

Change color of Spinner background w/ Sherlock not working


I am using the following code to change the color of the background of my spinner. I am confused as to why it is not work.

style.xml

<style name="MyTheme" parent="@style/Theme.Sherlock.Light">
    <item name="windowActionBarOverlay">true</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="actionDropDownStyle">@style/MyActionBarSpinnerStyle</item>

</style>

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

actionbar_spinner_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:drawable="@drawable/spinner_background_disabled" android:state_enabled="false"/>
  <item android:drawable="@drawable/spinner_background_pressed" android:state_pressed="true"/>
  <item android:drawable="@drawable/spinner_background_focused" android:state_focused="true" android:state_pressed="false"/>
  <item android:drawable="@drawable/spinner_background_default"/>
</selector>

Is there something that I am missing or doing incorrectly?

I have separate styles.xml files for default and 11+. This was from my 11+ file. I removed the true from my 11+ file and still not working. Testing on a device running 4.4.4 does it matter that I am using Sherlock?


Solution

  • The problem is that the following line of code require API level 11 and up :

    <item name="android:windowActionBarOverlay">true</item>
    

    Solution -

    Make separate styles.xml in res/values-v11 to support the same functionality in android 3.0 and up.

    For Android 3.0 and higher only

    If your minSdkVersion is set to 11 or higher, your custom theme should use Theme.Holo theme (or one of its descendants) as your parent theme.

    For example -

    <resources>
        <!-- the theme applied to the application or activity -->
        <style name="CustomActionBarTheme"
               parent="@android:style/Theme.Holo">
            <item name="android:windowActionBarOverlay">true</item>
        </style>
    </resources>
    

    For Android 2.1 and higher

    If your app is using the Support Library for compatibility on devices running versions lower than Android 3.0, your custom theme should use Theme.AppCompat theme (or one of its descendants) as your parent theme.

    For example -

    <resources>
        <!-- the theme applied to the application or activity -->
        <style name="CustomActionBarTheme"
               parent="@android:style/Theme.AppCompat">
            <item name="android:windowActionBarOverlay">true</item>
    
            <!-- Support library compatibility -->
            <item name="windowActionBarOverlay">true</item>
        </style>
    </resources>
    

    NOTE:

    Notice that this theme includes two definitions for the windowActionBarOverlay style: one with the android: prefix and one without. The one with the android: prefix is for versions of Android that include the style in the platform and the one without the prefix is for older versions that read the style from the Support Library.

    Reference:

    https://developer.android.com/training/basics/actionbar/overlaying.html#EnableOverlay