如何使 ImageView 的 Android 矢量资源不透明

How to make the an Android Vector asset for an ImageView non-transparent

我使用 Android studio 创建了一个 Vector 资产,我有以下代码:

<vector android:height="24dp" android:tint="#4CAC78"
    android:viewportHeight="24" android:viewportWidth="24"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="@android:color/white" android:pathData="M23,12l-2.44,-2.78 0.34,-3.68 -3.61,-0.82 -1.89,-3.18L12,3 8.6,1.54 6.71,4.72l-3.61,0.81 0.34,3.68L1,12l2.44,2.78 -0.34,3.69 3.61,0.82 1.89,3.18L12,21l3.4,1.46 1.89,-3.18 3.61,-0.82 -0.34,-3.68L23,12zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
    
</vector>

结果如下所示:

问题是感叹号是透明的,我想让它不透明。我试图更改属性 path android:fillColor="@android:color/black 但这没有任何效果。知道我该怎么做吗?

绿色区域和感叹号实际上是由两个单独的路径创建的,它们组合到矢量可绘制对象中的单个 path 语句中。要分别为它们着色,您需要将它们分成单独的路径语句:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path
        android:fillColor="#4CAC78"
        android:pathData="M23,12l-2.44,-2.78 0.34,-3.68 -3.61,-0.82 -1.89,-3.18L12,3 8.6,1.54 6.71,4.72l-3.61,0.81 0.34,3.68L1,12l2.44,2.78 -0.34,3.69 3.61,0.82 1.89,3.18L12,21l3.4,1.46 1.89,-3.18 3.61,-0.82 -0.34,-3.68L23,12z" />
    <path
        android:fillColor="@android:color/black"
        android:pathData="M13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z" />
</vector>