简体   繁体   English

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

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

I crated a Vector asset using Android studio and I have the following code:我使用 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>

The result looks like this:结果如下所示:

在此处输入图像描述

The problem is that the exclamation mark is transparent and I would like to make it non-transparent.问题是感叹号是透明的,我想让它不透明。 I tried to change the attribute path android:fillColor="@android:color/black but this did not have any effect. Any idea how I can do this?我试图更改属性path android:fillColor="@android:color/black但这没有任何效果。知道我该怎么做吗?

The green area and the exclamation mark are really created by two separate paths that are combined into the single path statement in the vector drawable.绿色区域和感叹号实际上是由两个单独的路径创建的,这些路径组合到矢量可绘制对象中的单个path语句中。 To color them separately, you need to separate them out into separate path statements:要分别为它们着色,您需要将它们分成单独的路径语句:

<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>

在此处输入图像描述

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

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