如何更改 ActionBar 溢出图标

How to change ActionBar overflow icon

以下是我的风格:

 <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!-- <item name="windowActionBar">false</item> -->
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
        <!-- <item name="actionBarStyle">@style/Theme.MyApp.ActionBar</item> -->
    </style>
 <style name="OverflowMenu" parent="Widget.AppCompat.PopupMenu.Overflow">

        <!-- Required for pre-Lollipop. -->
        <item name="overlapAnchor">false</item>

        <!-- Required for Lollipop. -->
        <!-- <item name="android:overlapAnchor">false</item> -->
    </style>

我正在使用 appcompat 支持库中的 ActionBarActivity 来更改溢出按钮的颜色。

  <style name="AppTheme" parent="AppBaseTheme">
        <item name="actionOverflowMenuStyle">@style/OverflowMenu</item>
        <item name="android:actionOverflowButtonStyle">@style/OverFlowStyle</item>

        <!-- <item name="actionBarStyle">@style/Theme.MyApp.ActionBar</item> -->
    </style>

    <style name="OverFlowStyle" parent="Widget.AppCompat.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_empty</item>
    </style>

正如您样式中的注释所暗示的,棒棒糖需要 android: 前缀。您是否也尝试过将其添加到 actionOverflowMenuStyle 属性?

<item name="android:actionOverflowButtonStyle">@style/OverflowMenu</item>
<item name="actionOverflowButtonStyle">@style/OverflowMenu</item>

对于 android 版本 < 21 应该是这样的。

<style name="AppTheme" parent="AppBaseTheme">

         ...
     <item name="actionOverflowButtonStyle">@style/OverFlowStyle</item>
</style>

<style name="OverFlowStyle" parent="Widget.AppCompat.ActionButton.Overflow">
    <item name="android:src">@drawable/ic_empty</item>
</style>
    <style name="OverFlowStyle" parent="@style/Widget.AppCompat.Light.ActionButton.Overflow">
            <item name="android:src">@drawable/green_overflow</item>
        </style>
    <style name="AppTheme" parent="AppBaseTheme">
    <item name="actionOverflowButtonStyle">@style/OverFlowStyle</item>
            <item name="android:actionOverflowButtonStyle">@style/OverFlowStyle</item>
</style>

使用工具栏,上面的 none 对我有用,我不得不通过代码更改它,使用以下代码:

public static void setOverflowButtonColor(final Activity activity) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            TintImageView overflow=(TintImageView) outViews.get(0);
            overflow.setColorFilter(Color.CYAN);
            removeOnGlobalLayoutListener(decorView,this);
        }
    });
}

Complete source.