androiddrop-down-menuandroid-actionbarshareactionprovider

Setting a custom background color on Actionbar ShareActionProvider dropdownlist


I'm trying to set a custom background color to ShareActionProvider dropdownlist, I already changed holo actionbar color using this http://jgilfelt.github.io/android-actionbarstylegenerator/

As you can see the highlighted point at below image I could change the actionbar background color to orange but the ShareActionProvider dropdownlist background color is still gray. Does anyone have any idea how can I change it editing my theme in styles.xml?

enter image description here

Thank you very much for your time.


Solution

  • You will need to override the attribute listPopupWindowStyle.

    From the looks of it, you're using Theme.Holo.Light. Add this to your base theme:

    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
        ....
        <item name="android:listPopupWindowStyle">@style/MyListPopupWindowStyle</item>
    </style>
    

    Now define MyListPopupWindowStyle like this:

    <style name="MyListPopupWindowStyle" parent="@android:style/Widget.Holo.Light.ListPopupWindow">
        <item name="android:popupBackground">@drawable/list_popup_background</item>
    </style>
    

    Next, create the drawable list_popup_background and you'll be done.

    Output:

    enter image description here

    By the way, in the screenshot above, I have used a ColorDrawable as the background. That's why, the corners are not rounded, and there's no drop shadow. For that, you'll need to create a nine-patch drawable, similar to the one that android uses. Here's what it looks like:

    enter image description here

    My ColorDrawable was defined as:

    <drawable name="list_popup_background">#33ffffff</drawable>
    

    Some more info:

    Android itself uses a state selector drawable for ListPopupWindow's background. The selector defines two states: state_above_anchor & state_below_anchor(reachable by default):

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_above_anchor="true" android:drawable="@android:drawable/menu_popup_panel_holo_light" />
        <item android:drawable="@android:drawable/menu_dropdown_panel_holo_light" />
    

    It might be a good idea for you to define something similar.