简体   繁体   English

如何从应用程序中引用Android材料图标?

[英]How to reference Android material icons from app?

I'm trying to use Android's material icons in a View from within my app. 我正试图在我的应用程序中的视图中使用Android的素材图标 I can't seem to find an example anywhere of how to reference them. 我似乎无法在任何地方找到如何引用它们的例子。 I can't imagine, for this standard set of icons, that I'm required to copy and paste them into my actual app under the res directory. 我无法想象,对于这个标准的图标集,我需要将它们复制并粘贴到res目录下的实际应用程序中。 Surely there must be a simpler way since 90% of Android apps are using the same drawables! 肯定有一个更简单的方法,因为90%的Android应用程序使用相同的drawables! What I'm looking for is something like: 我正在寻找的是:

<TextView
    ...
    android:drawableLeft="???" />

Is it possible to do this and reference the drawable from some package that I import? 是否可以这样做并从我导入的某个包中引用drawable? Or do I actually have to copy all the icons I want to use into my application resources? 或者我是否真的必须将我想要使用的所有图标复制到我的应用程序资源中? That seems completely unnecessary to me. 这对我来说似乎完全没用。

The developer guide says they're named */drawable-{{density}}/ic_{{name}}_{{color}}_{{size}}dp.png but it's precisely the * which I would like to know (and I hope it's not myapp/res/drawable !). 开发者指南说它们被命名为*/drawable-{{density}}/ic_{{name}}_{{color}}_{{size}}dp.png但它正是我想知道的* (我希望它不是myapp/res/drawable !)。

You can try Android Material Design Icon Generator plugin for Android Studio, If you are using Android Studio. 如果您使用的是Android Studio,可以试用Android Studio的Android Material Design图标生成器插件。 Link to the plugin development Git repo is here 链接到插件开发Git repo就在这里

It is Easy and convenient. 它简单方便。 You can go through the image set and get the name from the google material design official website and then, you search for it and you can add that one to your project without any hassel. 您可以浏览图像集并从谷歌材料设计官方网站获取名称,然后,您搜索它,您可以添加到您的项目没有任何hassel。

Yes, you have to copy all your icons to your res folder. 是的,您必须将所有图标复制到res文件夹。 It's been said by Google somewhere. Google曾在某处说过。 The "Material Icons" website clearly is oriented towards that and it makes it easier. “材料图标”网站显然是面向这个,它使它更容易。 One important reason to do this is that you'll want the icons to work not only in Lollipop, but also in previous Android versions. 这样做的一个重要原因是,您希望图标不仅可以在Lollipop中使用,还可以在以前的Android版本中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM