简体   繁体   English

如何在插入矢量资产后在drawable.xml中添加图标?

[英]How to add an icon in drawable.xml after inserting vector asset?

I wanted some additional icons for my android studio project so I added in drawable folder through New > Vector Asset. 我想为我的android studio项目添加一些额外的图标,所以我通过New> Vector Asset添加了drawable文件夹。 The problem here is my drawable.xml file doesn't recognize my ic_menu_logout file. 这里的问题是我的drawable.xml文件无法识别我的ic_menu_logout文件。 The code: 编码:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <item name="ic_menu_camera" type="drawable">@android:drawable/ic_menu_camera</item>
    <item name="ic_menu_gallery" type="drawable">@android:drawable/ic_menu_gallery</item>
    <item name="ic_menu_slideshow" type="drawable">@android:drawable/ic_menu_slideshow</item>
    <item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item>
    <item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item>
    <item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item>
    <item name="ic_menu_logout" type="drawable">@android:drawable/ic_menu_logout</item>
</resources>

The last line containing ic_menu_logout displays an error. 包含ic_menu_logout的最后一行显示错误。 Maybe I missed something or did something wrong. 也许我错过了什么或做错了什么。 Help me out here. 帮帮我吧 Thanks. 谢谢。

NOTE: 注意:

The ic_menu_logout is an .xml file itself: ic_menu_logout本身是一个.xml文件:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FF000000"
        android:pathData="M10.09,15.59L11.5,17l5,-5 -5,-5 -1.41,1.41L12.67,11H3v2h9.67l-2.58,2.59zM19,3H5c-1.11,0 -2,0.9 -2,2v4h2V5h14v14H5v-4H3v4c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>

仅将@android:drawable / ic_menu_logout替换为@ drawable / ic_menu_logout

Replace @android:drawable/ic_menu_logout by only @drawable/ic_menu_logout 仅将@android:drawable / ic_menu_logout替换为@ drawable / ic_menu_logout

This solved my issue, thank you! 这解决了我的问题,谢谢!

EDIT: I ran into this issue, because I started off using a Navigation Drawer Activity. 编辑:我遇到了这个问题,因为我开始使用导航抽屉活动。 This includes some drawables like ic_menu_gallery in the res/drawable-v21 folder. 这包括一些drawables,如res / drawable-v21文件夹中的ic_menu_gallery。 However, it also includes a values/drawables.xml which includes aliases for all the drawables! 但是,它还包含一个值/ drawables.xml,其中包含所有drawable的别名! These are specified as 这些被指定为

 <item name="ic_menu_camera" type="drawable">@android:drawable/ic_menu_camera</item>

which means that the android system drawables are always used and the drawables in the res/drawable-v21 folder are ignored. 这意味着总是使用android系统drawables,并忽略res / drawable-v21文件夹中的drawables。 You can validate this by changing the color of the drawables in res/drawables-v21 folder. 您可以通过更改res / drawables-v21文件夹中drawable的颜色来验证这一点。

My solution was to copy all the drawables from the drawables-v21 to the drawables folder and delete the drawables-v21 folder. 我的解决方案是将所有drawables从drawables-v21复制到drawables文件夹并删除drawables-v21文件夹。 I also deleted the values/drawable.xml file, as it completely useless and confuses people (me at least. ;)) 我还删除了values / drawable.xml文件,因为它完全没用并且让人感到困惑(至少我。))

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

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