是否可以更改操作栏中溢出按钮(3个垂直点)的颜色?如果可以,我们该如何做到呢?我没有找到任何关于溢出按钮的样式。
谢谢
是否可以更改操作栏中溢出按钮(3个垂直点)的颜色?如果可以,我们该如何做到呢?我没有找到任何关于溢出按钮的样式。
谢谢
<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>
parent="@android:style/Widget.ActionButton.Overflow"
。 - jokeefe<item name="android:textColorPrimary">@android:color/white</item>
就可以解决你的问题。
只有一个小问题是,这种颜色也会应用于你的溢出菜单的文本颜色,当然还有很多其他地方。 - Neo这些答案中有一些过于复杂,而有些又只能得到有限的结果。答案要简单得多。您可以随时将其设置为任何颜色。
toolbar.getOverflowIcon().setColorFilter(colorInt, PorterDuff.Mode.SRC_ATOP);
colorInt
,而是使用ContextCompat.getColor(this, R.color.gray)
。 - CoolMindsetTint
,因为 setColorFilter
已经被弃用:.setTint(ContextCompat.getColor(this, R.color.red))
。 - AlvaroSantistebanToolbar toolbar = findViewById(R.id.toolbar);
You can use a Toolbar in xml for the ActionBar by using the method setSupportActionBar(toolbar);
- John GlenXGouchet的回答非常好,但是我想补充一点,如果你继承一个现有的样式,你会得到标准的填充、选中状态等。
<style name="MyCustomTheme.OverFlow" parent="Widget.Sherlock.ActionButton.Overflow">
<item name="android:src">@drawable/title_moreicon</item>
</style>
其他编程选项:
Drawable drawable = toolbar.getOverflowIcon();
if(drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), getResources().getColor(R.color.thecolor));
toolbar.setOverflowIcon(drawable);
}
希望这能帮到你!
如果您正在使用AppCompat,您可以派生一个新的自定义样式,将属性android:textColorSecondary
设置为所需的颜色,并将其用作工具栏的主题。
Android:更改工具栏文本颜色和溢出图标颜色
放置图像并不是一个好主意,因为如果您只需更改颜色即可更改它,则无需使用额外的图像。
菜单点从textColorPrimary中选择颜色,因此,与其编写多行,这个单行代码
<item name="android:textColorPrimary">@android:color/white</item>
将解决您的问题。
唯一的小问题是,这个颜色也会应用于您的溢出菜单的文本颜色,当然还有许多其他地方 :)
<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>
要将溢出图标颜色更改为您选择的颜色.....使用它们
<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>
<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>
只需在style.xml文件中选择的样式中添加此行
<item name="colorControlNormal">@color/white</item>
它可以正常工作。 如果您使用
<item name="textColorSecondary">@color/white</item>
那么,您的其他项目,如抽屉导航菜单图标颜色和单选按钮,也会受到影响。
<item name="colorControlNormal">#fff</item>
添加到您的样式中。 - meyasir