0

Having the android.support.v7.widget.Toolbar and it's background color is changing based on different cases. The OverflowButton button (the three vertical dots at right of the toolbar) is always having the same background when press on it.

Saw some posts about how to change statically, like quoted below. But really want is to do it dynamically based the toolbar's background color.

Any idea?

To change statically:

You can change the image used for it using the following style declaration.

<style name="MyCustomTheme" parent="style/Theme.Holo">
    <item name="android:actionOverflowButtonStyle">@style/MyCustomTheme.OverFlow</item>
</style>

<style name="MyCustomTheme.OverFlow">
    <item name="android:src">@drawable/my_overflow_image</item>
</style>

And if you're using ActionBarSherlock, here's how to do it

<style name="MyCustomTheme" parent="style/Theme.Sherlock">
    <item  name="android:actionOverflowButtonStyle">@style/MyCustomTheme.OverFlow</item>
    <item name="actionOverflowButtonStyle">@style/MyCustomTheme.OverFlow</item>
</style>

<style name="MyCustomTheme.OverFlow">
    <item name="android:src">@drawable/my_overflow_image</item>
</style>
Community
  • 1
  • 1
lannyf
  • 9,865
  • 12
  • 70
  • 152

1 Answers1

0

Edit-- The answer should be: It could be achieved by just to set partial transparent background in the style of actionOverflowButtonStyle so that whatever the toolbar's color will be blended in.

one solution might be just disable the press state by making it transparent for all toolbars, but it is no desirable.

Another one found, but feel like a hack. Not sure if anyone have better way to get access to the overflow button so it's background could be set dynamically with proper drawable.

from this bug report,

it could be done as the following setupOverflowMenuButton().

public boolean setupOverflowMenuButton (Menu menu, Toolbar toolbar) {
    Toolbar t = toolbar;
    for(int i = 0; i < t.getChildCount(); i++) {
        if(t.getChildAt(i) instanceof ActionMenuView) {
            ActionMenuView v = (ActionMenuView)t.getChildAt(i);
            for(int j = 0; j < v.getChildCount(); j++) {
                if(v.getChildAt(j) instanceof TintImageView) {
                    TintImageView v1 = (TintImageView)v.getChildAt(j);

v1.setBackgroundResource(R.drawable.overflow_bt_bg_selector);
                 }
            }
        }
    }
    return super.onPrepareOptionsMenu(menu);
}
lannyf
  • 9,865
  • 12
  • 70
  • 152
  • It could be achieved by just to set partial transparent background in the style of actionOverflowButtonStyle so that whatever the toolbar's color will be blended in. – lannyf Feb 14 '15 at 23:43