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.


您可以通过colorBackground属性对其进行着色

<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>
链接地址: http://www.djcxy.com/p/89630.html

上一篇: 在iOS逻辑测试中使用CocoaPods时未找到库

下一篇: 在操作栏ShareActionProvider下拉列表上设置自定义背景颜色