自定义默认导航抽屉活动矢量图标

时间:2016-06-09 17:09:04

标签: java android android-5.0-lollipop drawable

我正在尝试自定义和着色Android Studio 2.1.2上的默认Navigation Drawer Activity。我已按以下方式更改了ic_menu_camera.xml文件的颜色 -

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="24.0"
    android:viewportWidth="24.0">
    <path
        android:fillColor="#f73a3a" //changed colour
        android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
    <path
        android:fillColor="#f73a3a" //changed colour
        android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
</vector>

预览窗口中的颜色会发生变化,如下面的屏幕截图所示 -

enter image description here

然而,当应用程序启动时,颜色会再次更改为默认的黑/深灰色 -

enter image description here

如何在此处实现更改后的颜色?

1 个答案:

答案 0 :(得分:0)

您需要在setItemIconTintList

期间将onCreate设置为空
YourView.setItemIconTintList(null);

现在,您可以直接编辑矢量资源,并显示更改。