Android Studio从矢量图形中替换颜色

时间:2018-03-22 22:50:39

标签: android android-studio svg vector-graphics

我以.svg格式下载了Google徽标,如下所示:here

但是,当我在Android Studio中导入时,徽标会将蓝色替换为绿色,并在设备上显示蓝色(绿色代替)。

enter image description here

1 个答案:

答案 0 :(得分:1)

I tried importing the same icon into an empty project, I saw the same behavior as you. If you click the little "Override" button on/off it seemed to fix the problem, if only temporarily. The below XML shows the correct coloring for me, try pasting it directly into your current file:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="48.0"
    android:viewportWidth="48.0">
    <group>
        <clip-path android:pathData="M44.5,20H24v8.5h11.8C34.7,33.9 30.1,37 24,37c-7.2,0 -13,-5.8 -13,-13s5.8,-13 13,-13c3.1,0 5.9,1.1 8.1,2.9l6.4,-6.4C34.6,4.1 29.6,2 24,2 11.8,2 2,11.8 2,24s9.8,22 22,22c11,0 21,-8 21,-22 0,-1.3 -0.2,-2.7 -0.5,-4z M 0,0" />
        <path
            android:fillColor="#FBBC05"
            android:pathData="M0 37V11l17 13z" />
    </group>
    <group>
        <clip-path android:pathData="M44.5,20H24v8.5h11.8C34.7,33.9 30.1,37 24,37c-7.2,0 -13,-5.8 -13,-13s5.8,-13 13,-13c3.1,0 5.9,1.1 8.1,2.9l6.4,-6.4C34.6,4.1 29.6,2 24,2 11.8,2 2,11.8 2,24s9.8,22 22,22c11,0 21,-8 21,-22 0,-1.3 -0.2,-2.7 -0.5,-4z M 0,0" />
        <path
            android:fillColor="#EA4335"
            android:pathData="M0 11l17 13 7,-6.1L48 14V0H0z" />
    </group>
    <group>
        <clip-path android:pathData="M44.5,20H24v8.5h11.8C34.7,33.9 30.1,37 24,37c-7.2,0 -13,-5.8 -13,-13s5.8,-13 13,-13c3.1,0 5.9,1.1 8.1,2.9l6.4,-6.4C34.6,4.1 29.6,2 24,2 11.8,2 2,11.8 2,24s9.8,22 22,22c11,0 21,-8 21,-22 0,-1.3 -0.2,-2.7 -0.5,-4z M 0,0" />
        <path
            android:fillColor="#34A853"
            android:pathData="M0 37l30,-23 7.9 1L48 0v48H0z" />
    </group>
    <group>
        <clip-path android:pathData="M44.5,20H24v8.5h11.8C34.7,33.9 30.1,37 24,37c-7.2,0 -13,-5.8 -13,-13s5.8,-13 13,-13c3.1,0 5.9,1.1 8.1,2.9l6.4,-6.4C34.6,4.1 29.6,2 24,2 11.8,2 2,11.8 2,24s9.8,22 22,22c11,0 21,-8 21,-22 0,-1.3 -0.2,-2.7 -0.5,-4z M 0,0" />
        <path
            android:fillColor="#4285F4"
            android:pathData="M48 48L17 24l-4,-3 35,-10z" />
    </group>
</vector>