如何设置MenuItem的图标颜色? [英] How to set icon color of MenuItem?
问题描述
我定义了一个具有ShareActionProvider并共享白色图标的菜单项,如下所示:
I defined a menu item that has ShareActionProvider and share white icon like so :
<item
android:icon="@drawable/ic_share_white_24dp"
android:id="@+id/action_share"
android:title="@string/action_share"
android:orderInCategory="200"
app:showAsAction="ifRoom"
app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/>
但是,当我启动该应用程序时,我得到了一个不同的黑色共享图标.如何将共享图标设置为白色?
But when I launch the application, I get a different black share icon. How to set the share icon to be white?
这是我得到的结果
推荐答案
这是一个主题问题.根据您当前的主题,您需要设置正确的ActionBar叠加主题.动作提供程序读取主题中的值(指示主题是深色还是浅色),以确定图标的颜色.
This is a theming issue. Depending on your current theme, you need to set the correct ActionBar overlay theme. The Action Provider reads a value in the theme (which indicates if the theme is dark or light) to determine the color of the icon.
如果主主题是浅色,而ActionBar是黑暗,则您的ActionBar/工具栏必须使用主题ThemeOverlay.AppCompat.Dark.ActionBar
.
If your main theme is light and your ActionBar is dark, your ActionBar/Toolbar must use the theme ThemeOverlay.AppCompat.Dark.ActionBar
.
这篇关于如何设置MenuItem的图标颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!