色调菜单图标 [英] Tint menu icons
问题描述
我要建一个Android应用程序,我用从操作栏图标包的图标操作栏中使用。我通过菜单
文件夹中的XML文件中定义它们。
有没有一种方法来色调这些图标,使他们都是一样的颜色?
到目前为止,我必须用图像编辑软件,做手工,但如果我决定改变颜色,我要全部做一遍。
I'm building an Android app and I use the icons from the Action Bar Icon Pack to use in the action bar. I define them through the xml files in the menu
folder.
Is there a way to "tint" these icons so that they are all the same color?
So far, I have to do it manually with an image editing software but if I decide to change the color, I have to do it all over again.
我知道有一个安卓色调
属性的ImageView
,但我还没有找到一个方法来使用它的菜单的图标。
I know there is a android:tint
attribute for ImageView
but I haven't found a way to use it for the menu's icons.
感谢
推荐答案
有可能是一个更好的办法做到这一点,但其中一个方案是重新绘制在code中的图标。
There may be a better way to do this, but one option is to redraw the icon in code.
假设你有一个收藏夹菜单项,并希望其着色灰色的:
Suppose you have a menu item for favorites and want to tint it gray:
MenuItem favoriteItem = menu.findItem(R.id.action_favorite);
Drawable newIcon = (Drawable)favoriteItem.getIcon();
newIcon.mutate().setColorFilter(Color.argb(255, 200, 200, 200), PorterDuff.Mode.SRC_IN);
favoriteItem.setIcon(newIcon);
您也可以使用像
newIcon.mutate().setColorFilter(getResources().getColor(R.color.myCustomTint), PorterDuff.Mode.SRC_IN);
这篇关于色调菜单图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!