对于我的项目,我想使用矢量图像作为图标,但我遇到了一个问题。当我使用android:fillColor
的渐变时,android:strokeColor
和android:strokeWidth
定义的边框下方的代码不会出现在应用中。将android:fillColor
直接添加到path
时,它会起作用,但之后我会失去渐变。
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="32dp"
android:height="56dp"
android:viewportHeight="56.0"
android:viewportWidth="32.0">
<path
android:fillType="evenOdd"
android:pathData="M4,1L28,1A3,3 0,0 1,31 4L31,52A3,3 0,0 1,28 55L4,55A3,3 0,0 1,1 52L1,4A3,3 0,0 1,4 1z"
android:strokeColor="#000000"
android:strokeWidth="1.4">
<aapt:attr name="android:fillColor">
<gradient
android:endX="17.0"
android:endY="56.0"
android:startX="17.0"
android:startY="2.0"
android:type="linear">
<item
android:color="#FFFFFFFF"
android:offset="0.0" />
<item
android:color="#FFD1D2D1"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
...
</vector>
这就是我现在使用的Nexus 5X和Pixel 2 XL仿真器:
这就是我想要实现的目标。这是我从Android Studio中截取的屏幕截图的一部分,它可以正确呈现矢量: