rekire
rekire

Reputation: 47945

Themeing the Popup of the ShareActionProvider from ActionBarSherlock

I want to theme the ShareActionProvider of the ActionBarSherlock. My problem is that I successfully customized the styles of the ActionBar but I cannot style the share popup which comes from the ActionBarSherlock.

Share and Menu example

In the Screenshot above you can see the share popup uses the default styles while a normal more popup is styled in that way I like.

I digged more thrue the source code and found in ActivityChooserView this method:

private IcsListPopupWindow getListPopupWindow() {
    if (mListPopupWindow == null) {
        mListPopupWindow = new IcsListPopupWindow(getContext());
        //...

Which is as far I know responsable for creating that Popup of the ShareActionProvider. As you can see above a new instance of IcsListPopupWindow is created. Here are the constructors of IcsListPopupWindow:

public IcsListPopupWindow(Context context) {
    this(context, null, R.attr.listPopupWindowStyle);
}

public IcsListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr) {
    mContext = context;
    mPopup = new PopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
}

So far the attr com.actionbarsherlock.R.attr.listPopupWindowStyle used. While this attr is inserted the one and two parameter constructor of IcsListPopupWindow created a new PopupWindow with the attr com.android.internal.R.attr.popupWindowStyle which seems to be equal with android.R.attr.popupWindowStyle:

public PopupWindow(Context context, AttributeSet attrs) {
    this(context, attrs, com.android.internal.R.attr.popupWindowStyle);
}

public PopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;
    mWindowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);

    TypedArray a =
        context.obtainStyledAttributes(
            attrs, com.android.internal.R.styleable.PopupWindow, defStyleAttr, defStyleRes);

    mBackground = a.getDrawable(R.styleable.PopupWindow_popupBackground);

    // ...

There you can see that the background image is loaded from a style called styleable.PopupWindow_popupBackground. I tried to apply my style with this xml file:

<style name="Theme.MyStyle" parent="@style/Theme.Sherlock.Light.DarkActionBar">
    <!-- ... -->
    <item name="actionDropDownStyle">@style/DropDownNav.MyStyle</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.MyStyle</item>
    <item name="actionBarItemBackground">@drawable/selectable_background_mystyle</item>
    <item name="listPopupWindowStyle">@style/DropDownNav.MyStyle</item>
    <item name="android:listPopupWindowStyle">@style/DropDownNav.MyStyle</item>
</style>

<style name="DropDownNav.MyStyle" parent="@style/Widget.Sherlock.Spinner.DropDown.ActionBar">
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_mystyle</item>
    <item name="android:divider">#081925</item>
    <item name="android:dividerHeight">1dp</item>
</style>

<style name="DropDownListView.MyStyle" parent="@style/Widget.Sherlock.ListView.DropDown">
    <item name="android:divider">#081925</item>
    <item name="android:dividerHeight">1dp</item>
</style>

But it does not work. What am I doing wrong?
By the way I would be really happy if someone could give me a good tutorial for styleable and the attr stuff I don't get it right.

Upvotes: 2

Views: 2513

Answers (1)

hitch45
hitch45

Reputation: 492

I was able to override the popupBackground color by overriding this ABS style:

<style name="Widget.Sherlock.Light.ListPopupWindow" parent="Widget">
    <item name="android:popupBackground">#333333</item>
</style>

Hopefully that can get you going. And if you were able to solve it on your own, please share with the rest of us how you styled the rest of the attributes. Cheers

Upvotes: 3

Related Questions