是否可以更改操作栏上的溢出按钮(3个垂直点)的颜色? 如果是这样,我们该怎么做?我没有找到溢出按钮的任何样式。
由于
答案 0 :(得分:66)
您可以使用以下样式声明更改用于它的图像。
<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>
答案 1 :(得分:20)
XGouchet's answer很棒,但只是想补充一点,如果从现有样式继承,你将获得标准填充,选定状态等。
<style name="MyCustomTheme.OverFlow" parent="Widget.Sherlock.ActionButton.Overflow">
<item name="android:src">@drawable/title_moreicon</item>
</style>
答案 2 :(得分:17)
其中一些答案是严重的过大杀伤力,有些则给出的结果有限。答案要简单得多。您可以随时将其设置为所需的任何颜色。 在这里:
toolbar.getOverflowIcon().setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP);
答案 3 :(得分:9)
如果您使用的是AppCompat,则可以将属性(?: [A-Z]+)?
设置为所需颜色的新自定义样式派生,并将其用作工具栏的主题。
Android: Changing the Toolbar’s text color and overflow icon color
答案 4 :(得分:4)
其他以编程方式选项:
Drawable drawable = toolbar.getOverflowIcon();
if(drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), getResources().getColor(R.color.thecolor));
toolbar.setOverflowIcon(drawable);
}
希望它有所帮助!
答案 5 :(得分:2)
放置图像并不是一个好主意,因为如果你可以通过改变颜色来改变它,那么就不需要使用额外的图像了。
菜单点从textColorPrimary中选择颜色,因此不是在这一行中写入多行
<item name="android:textColorPrimary">@android:color/white</item>
会解决您的问题。
只有一个小问题是这种颜色也适用于溢出菜单的文本颜色,当然还有很多其他地方:)
答案 6 :(得分:1)
<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的答案仅适用于Lollipop和更高级别的设备,而我的适用于所有API 7+设备。
参考:Custom AppCompat Theme not changing Overflow icon on older devices
答案 7 :(得分:1)
如果您使用的是最新的工具栏,则必须将该语句放在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>
答案 8 :(得分:1)
只需在style.xma文件中选择的样式中添加此行
<item name="colorControlNormal">@color/white</item>
工作正常。 如果你使用
<item name="textColorSecondary">@color/white</item>
然后您的其他项目,如抽屉导航菜单图标颜色和单选按钮将受到影响
答案 9 :(得分:0)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.dashboard, menu); // dashboard is xml file name
Drawable drawable = menu.findItem(R.id.lan).getIcon();
if (drawable != null) {
drawable.mutate();
drawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
}
return true;
}
它为我工作,我从 here
找到了它答案 10 :(得分:0)
要更改“溢出”图标的颜色,只需添加
toolbar.setOverflowicon(getDrawable)
答案 11 :(得分:0)
要将溢出图标的颜色更改为您选择的颜色.....使用它们
<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>
答案 12 :(得分:-1)
如果只想让3点图标变成白色而不是黑色,则只需将工具栏的主题更改为此:
<android.support.v7.widget.Toolbar
...
android:theme="@android:style/ThemeOverlay.Material.Dark.ActionBar"
/>
此处完整参考: medium.com/the-curious-case-of-the-overflow-icon-color