如何更改ActionBar溢出图标

时间:2015-04-10 12:06:30

标签: android android-actionbar android-actionbar-compat

以下是我的风格:

 <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>

4 个答案:

答案 0 :(得分:2)

    <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>

答案 1 :(得分:1)

正如你的风格中的评论所暗示的那样,棒棒糖需要android:前缀。您是否尝试过将其添加到actionOverflowMenuStyle属性?

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

答案 2 :(得分:1)

对于Android版本&lt; 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>

答案 3 :(得分:1)

使用工具栏,以上都不适合我,我不得不通过代码更改它,使用以下内容:

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.