如何在Android工具栏中设置图标的颜色? [英] How to set the color of icon in Android toolbar?

查看:123
本文介绍了如何在Android工具栏中设置图标的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 https://github.com/nglauber分叉了一个GitHub项目. /playground/tree/master/android/DemoSearch

我想将搜索图标的颜色设置为纯白色.目前,搜索图标为灰色,与演示搜索"的白色文本明显不同.

I would like to set the color of the search icon to be pure white. At the moment, the search icon is gray in color, and is obviously different from the white text of "Demo Search".

根据一些建议,我使用纯白色(准确地说是RGB = 255,255,255)创建了一个新图标,并使用它代替了android:ic_menu_search.即使原始图标为纯白色,Android也会将其设置为灰色色调(已通过屏幕截图中的颜色选择器工具进行了验证).

Based on some suggestions, I created a new icon using pure white (to be exact, RGB=255,255,255), and use it in place of the android:ic_menu_search. Android will tint it with a gray tone (verified with color picker tool on the screenshot), even though the original icon is in pure white.

这向我表明Android故意为图标着色.我希望可以通过某种方式使用于在Android工具栏中设置或更改图标颜色的控件.

This suggests to me that Android is tinting the icon on purpose. And I hope there is some way I can have the control to set or change the icon color in the Android Toolbar.

推荐答案

我找到了自己问题的答案.我决定对其进行记录,以便能够为其他Android开发人员提供帮助.

I found the answer to my own question. I decided to document it so it will be able to help other Android developers.

最简单的答案是是,我们可以在Android工具栏中维护图标颜色,我们需要通过

The short answer is yes, we can maintain the icon color in the Android Toolbar, and we need to do it by importing the resource through

  • SVG ,或
  • 图标类型为启动器图标的PNG
  • SVG, or
  • PNG with icon type as Launcher Icons

我遇到的原始问题是由于

The original problem that I encountered was due to

  • 图标类型为操作栏和标签图标的PNG

在此设置中,Android Studio Image Asset保存到res项目文件夹时,出于某种未知的原因,图标颜色会略有更改.当图标最终显示在屏幕上时,Android将进一步更改其颜色.最终结果是我在问题中描述的内容,原来的纯白色图标将变成灰色.

In this setting, Android Studio Image Asset will change the icon color a little for some unknown reason when it saves to the res project folder. And Android will further change the icon color when it is finally displayed on the screen. The end result was what I described in the question, where the originally pure white icon will turn and become gray in color.

如果我们使用图标类型为SVG或PNG的启动器图标,则图标的颜色不会更改.该图标将能够保留其原始颜色.这使我相信它是Android Studio中的错误,而不是设计指南的帮助.

If we use SVG or PNG with icon type as Launcher Icons, there will be NO color change to the icon. The icon will be able to retain its original color. This makes me believe it is a bug in Android Studio rather than a design guideline assistance.

在此堆栈溢出帖子中报告了类似的观察结果. @markj报告生成的图像只是无用的灰色形状".

Similar observation is reported in this Stack Overflow post. @markj reported "the resulting images are just useless gray shapes".

生成的Android环境屏幕截图

The resulting Android environment screenshots

保持颜色

(SVG) (PNG为启动器图标)

(SVG) (PNG as Launcher Icons)

颜色已更改

(PNG为操作栏和选项卡图标)

(PNG as Action Bar and Tab Icons)

这篇关于如何在Android工具栏中设置图标的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆