Hi folks, I using image component like this; `Ima...
# compose
t
Hi folks, I using image component like this;
Image(
imageVector = ImageVector.vectorResource(id = someXmlDrawable)
But its crashing in Api 23. I replaced to like this
Image(
painter = painterResource(id = somePngDrawable)
And it works. Do u any idea ?
j
Whats the crash? Also what is the vector resource contains? There is some SVG elements/attributes not supported in Api 23 I think.
Copy code
<https://developer.android.com/develop/ui/views/graphics/vector-drawable-resources#vector-drawables-backward-solution>
I think Android Studio also has possiblity of adding vector drawable from svg, and auto convert non supported things like ``fillColor`,
fillType
and `strokeColor`` (Android 7+ required) automatic.
t
Thanks for your answer Joel, that is my svg, it’s include fillColor and fillType except strokeColor
Copy code
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="15dp"
    android:height="14dp"
    android:viewportWidth="15"
    android:viewportHeight="14">
  <path
      android:pathData="M6.251,5.333C6.251,4.697 6.728,4.163 7.36,4.091C7.991,4.02 8.576,4.433 8.719,5.053C8.861,5.672 8.517,6.3 7.917,6.512C7.418,6.688 7.084,7.161 7.084,7.691V8.25C7.084,8.48 7.271,8.666 7.501,8.666C7.731,8.666 7.917,8.48 7.917,8.25V7.691C7.917,7.514 8.029,7.356 8.195,7.297C9.194,6.944 9.769,5.898 9.531,4.865C9.293,3.833 8.318,3.144 7.265,3.263C6.213,3.383 5.418,4.273 5.417,5.333C5.417,5.563 5.604,5.75 5.834,5.75C6.064,5.75 6.251,5.563 6.251,5.333Z"
      android:fillColor="#FF6000"/>
  <path
      android:pathData="M6.876,10.125C6.876,10.47 7.155,10.75 7.501,10.75C7.846,10.75 8.126,10.47 8.126,10.125C8.126,9.78 7.846,9.5 7.501,9.5C7.501,9.5 7.501,9.5 7.501,9.5C7.156,9.5 6.876,9.78 6.876,10.125Z"
      android:fillColor="#FF6000"/>
  <path
      android:pathData="M14.167,7C14.167,10.682 11.182,13.666 7.501,13.666C3.819,13.666 0.834,10.682 0.834,7C0.834,3.318 3.819,0.333 7.501,0.333C11.182,0.333 14.167,3.318 14.167,7ZM1.667,7C1.667,10.221 4.279,12.833 7.501,12.833C10.722,12.833 13.334,10.221 13.334,7C13.334,3.778 10.722,1.166 7.501,1.166C4.279,1.166 1.667,3.778 1.667,7Z"
      android:fillColor="#FF6000"
      android:fillType="evenOdd"/>
</vector>
j
Yeah thats the problem then. Either need to convert those for below Android 7 or using Compat library, OR convert your vector to supported format working for API levels your app requires 🙂
Also be careful with below Android 6, then more things not working 😄
t
Okey, I just read document, thanks for sharing Joel 🙏 have a good day