简体   繁体   中英

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?

在此输入图像描述

Thank you very much for your time.

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 :

在此输入图像描述

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:

在此输入图像描述

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.

You can tint it via colorBackground attribute.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="actionBarTheme">@style/AppTheme.ActionBar</item>
</style>

<style name="AppTheme.ActionBar" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:colorBackground">@color/red</item>
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM