Android 更改 ActionBar 上溢出按钮的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11425660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change color of the overflow button on ActionBar
提问by Gaurav
Is it possible to change the color of the overflow button(3 vertical dots) on the action bar? If so, how do we do that? I didn't find any style for overflow button.
是否可以更改操作栏上溢出按钮(3 个垂直点)的颜色?如果是这样,我们该怎么做?我没有找到溢出按钮的任何样式。
Thanks
谢谢
回答by XGouchet
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
如果您使用的是 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>
回答by Peter Griffin
Some of these answers are serious overkill and some give limited results. The answer is much simpler. You can set it to whatever color you want, any time. Here:
其中一些答案是严重的矫枉过正,有些给出的结果有限。答案要简单得多。您可以随时将其设置为您想要的任何颜色。这里:
toolbar.getOverflowIcon().setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP);
回答by Brian Christensen
XGouchet's answeris great, but just wanted to add that if you inherit from an existing style you'll get the standard padding, selected state, etc.
XGouchet 的回答很好,但只是想补充一点,如果您从现有样式继承,您将获得标准填充、选定状态等。
<style name="MyCustomTheme.OverFlow" parent="Widget.Sherlock.ActionButton.Overflow">
<item name="android:src">@drawable/title_moreicon</item>
</style>
回答by ben_joseph
If you are using AppCompat , you could derive a new custom style with the attribute android:textColorSecondary
set to the required color, and use it as the theme for your toolbar.
Android: Changing the Toolbar's text color and overflow icon color
如果您使用 AppCompat ,您可以派生一个新的自定义样式,并将属性android:textColorSecondary
设置为所需的颜色,并将其用作工具栏的主题。
Android:更改工具栏的文本颜色和溢出图标颜色
回答by jos
Other programmatically option:
其他编程选项:
Drawable drawable = toolbar.getOverflowIcon();
if(drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), getResources().getColor(R.color.thecolor));
toolbar.setOverflowIcon(drawable);
}
Hope it helps!
希望能帮助到你!
回答by Neo
Putting images is not a great idea, because if you can change it by changing colors only then no need to use an extra image.
The menu dots picks color from textColorPrimary, so rather than writing multiple lines this single line
<item name="android:textColorPrimary">@android:color/white</item>
will fix your problem.
Only a small problem is that this color will be apply to the textcolor of your overflow menu also, and lots of other places of-course :)
放置图像不是一个好主意,因为如果您可以通过更改颜色来更改它,则无需使用额外的图像。菜单点从 textColorPrimary 中选取颜色,因此该单行<item name="android:textColorPrimary">@android:color/white</item>
将解决您的问题,而不是写多行
。只有一个小问题是这种颜色也将应用于溢出菜单的文本颜色,当然还有很多其他地方:)
回答by user8148577
<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>
Note that this is different from XGouchet's answer by removing android namespace. XGouchet's answer only works for Lollipop and higher devices while mine works for all API 7+ devices.
请注意,通过删除 android 命名空间,这与 XGouchet 的答案不同。XGouchet 的答案仅适用于 Lollipop 和更高版本的设备,而我的适用于所有 API 7+ 设备。
ref: Custom AppCompat Theme not changing Overflow icon on older devices
回答by Joseph Lam
If you are using the latest Toolbar, you have to put the statement in styles.xml, as shown in the code below:
如果您使用的是最新的 Toolbar,则必须将语句放在 style.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>
回答by Vipendra Singh
just add this line in your choosen style in style.xma file
只需在 style.xma 文件中以您选择的样式添加此行
<item name="colorControlNormal">@color/white</item>
<item name="colorControlNormal">@color/white</item>
its working fine. if you use
它的工作正常。如果你使用
<item name="textColorSecondary">@color/white</item>
<item name="textColorSecondary">@color/white</item>
then your other items like drawer navigation menu icons color and radio button will be affected
那么您的其他项目,如抽屉导航菜单图标颜色和单选按钮将受到影响
回答by victor
To change overflow icon color to color of your choice..... User them
要将溢出图标颜色更改为您选择的颜色..... 使用它们
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="actionOverflowButtonStyle">@style/actionButtonOverflow</item>
</style>
<style name="actionButtonOverflow" parent="Widget.AppCompat.Light.ActionButton.Overflow">
<item name="android:tint">@color/primary_dark</item>
</style>