如果我使用android:src =“ @ drawable / myicon”,则我在Android 5.0.1上错误地将矢量绘制为全白,而使用app:srcCompat可以正确显示它。我认为Android 5已经支持矢量可绘制对象,并且您不再需要app:srcCompat吗?我在AppCompatActivity中使用它,这是可绘制对象:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="45dp"
android:height="45dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:pathData="M22.2222,31.1111l8.8889,0l0,-8.8889l-8.8889,0z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:pathData="M8.8889,31.1111l8.8889,0l0,-8.8889l-8.8889,0z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:pathData="M22.2222,17.7778l8.8889,0l0,-8.8889l-8.8889,0z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:pathData="M0,40L40,40L40,0L0,0L0,40ZM4.4444,35.5556L35.5556,35.5556L35.5556,4.4444L4.4444,4.4444L4.4444,35.5556Z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
<path
android:fillColor="#FFFFFF"
android:fillType="evenOdd"
android:pathData="M8.8889,17.7778l8.8889,0l0,-8.8889l-8.8889,0z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
答案 0 :(得分:0)
根据我的经验,在某些Android版本中,矢量可绘制对象仍然存在许多问题,这些问题可以通过app:srcCompat来解决,至少使用AppCompatActivity可以解决。我想这是因为使用app:srcCompat使用了不同的代码来处理此属性,该属性可能正在解决最初未在Android框架版本中解决的问题。