更改ActionBar上溢出button的颜色

是否可以更改操作栏上溢出button的颜色(3个垂直点)? 如果是这样,我们该怎么做? 我没有find任何溢出button的样式。

谢谢

您可以使用以下样式声明更改用于它的图像。

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

如果你使用的是ActionBarSherlock,下面是如何做到这一点

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

XGouchet的答案很好,但是只是想补充一点,如果你从现有的风格inheritance,你会得到标准的填充,select状态等。

 <style name="MyCustomTheme.OverFlow" parent="Widget.Sherlock.ActionButton.Overflow"> <item name="android:src">@drawable/title_moreicon</item> </style> 

创build这个方法:

 public static void setOverflowButtonColor(final Activity activity, final int color) { 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; } AppCompatImageView overflow = (AppCompatImageView) outViews.get(0); overflow.setColorFilter(color); removeOnGlobalLayoutListener(decorView, this); } }); } 

然后像这样调用它:

 setOverflowButtonColor(this, getResources().getColor(R.color.hot_pink)); 

如果您使用AppCompat,则可以使用属性android:textColorSecondary派生一个新的自定义样式,将其设置为所需的颜色,并将其用作工具栏的主题。 Android:更改工具栏的文字颜色和溢出图标颜色

放置图像不是一个好主意,因为如果你可以通过改变颜色来改变它,那么不需要使用额外的图像。 菜单点从textColorPrimary中选取颜色,所以不用多行写这行<item name="android:textColorPrimary">@android:color/white</item>会解决你的问题。 只有一个小问题是,这种颜色将适用于你的溢出菜单的文本颜色也很多其他地方的当然:)

其他编程选项:

  Drawable drawable = toolbar.getOverflowIcon(); if(drawable != null) { drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable.mutate(), getResources().getColor(R.color.thecolor)); toolbar.setOverflowIcon(drawable); } 

希望能帮助到你!

 <style name="MyCustomTheme" parent="@style/Theme.AppCompat.Light"> <item name="actionOverflowButtonStyle">@style/OverflowMenuButtonStyle</item> </style> <style name="OverflowMenuButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow"> <item name="android:src">@drawable/quantum_ic_more_vert_white_24</item> </style> 

请注意,这是不同于XGouchet的回答,通过删除android命名空间。 XGouchet的答案只适用于棒棒糖和更高的设备,而矿山适用于所有API 7+设备。

ref: 自定义AppCompat主题不更改旧设备上的溢出图标

如果您使用的是最新的工具栏,则必须将该语句放在styles.xml中,如下面的代码所示:

 <style name="AppToolbar" parent="ThemeOverlay.AppCompat.Dark.ActionBar"> <item name="android:textColorPrimary">@android:color/white</item> <item name="android:textColorSecondary">@android:color/black</item> </style>