How can I convert my android vector drawable to SVG?
Don't mark it as duplicate question. I have already tried those methods but didn't work, what I have tried https://shapeshifter.design/ website, but actually it is good, but it gives me wrong input and output.
Suppose I have a vector
<vector android:height="80dp" android:viewportHeight="512"
android:viewportWidth="512" android:width="80dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#color/colorLightYellow" android:pathData="M150.561,144.549c-1.315,0 -2.647,-0.341 -3.86,-1.06L52.164,87.532c-3.609,-2.136 -4.803,-6.793 -2.667,-10.402c2.137,-3.608 6.793,-4.802 10.402,-2.667l94.537,55.957c3.609,2.136 4.803,6.793 2.667,10.402C155.685,143.217 153.156,144.549 150.561,144.549z"/>
<path android:fillColor="#color/colorLightYellow" android:pathData="M150.568,144.548H47.842c-4.194,0 -7.593,-3.399 -7.593,-7.593s3.4,-7.593 7.593,-7.593h102.727c4.194,0 7.593,3.399 7.593,7.593S154.762,144.548 150.568,144.548z"/>
<path android:fillColor="#color/colorLightOrange" android:pathData="M342.693,335.833L207.961,136.955l51.811,-74.838c10.849,-15.671 -0.367,-37.077 -19.426,-37.077H118.183c-19.059,0 -30.275,21.406 -19.426,37.077l51.811,74.838L15.836,335.833C5.516,351.066 0,369.043 0,387.443l0,0c0,50.82 41.198,92.018 92.017,92.018h174.495c50.82,0 92.017,-41.198 92.017,-92.018l0,0C358.529,369.043 353.013,351.066 342.693,335.833z"/>
<path android:fillColor="#color/colorLightOrange" android:pathData="M342.693,335.833L207.961,136.955l51.811,-74.838c10.849,-15.671 -0.367,-37.077 -19.426,-37.077h-22.144c17.303,0 27.486,21.406 17.637,37.077l-47.038,74.838L311.12,335.833c9.369,15.233 14.377,33.211 14.377,51.61c0,50.82 -37.402,92.018 -83.539,92.018h24.555c50.82,0 92.017,-41.198 92.017,-92.018C358.529,369.043 353.013,351.066 342.693,335.833z"/>
<path android:fillColor="#color/colorLightYellow" android:pathData="M214.129,144.548h-71.883c-4.194,0 -7.593,-3.399 -7.593,-7.593s3.4,-7.593 7.593,-7.593h71.883c4.194,0 7.593,3.399 7.593,7.593S218.323,144.548 214.129,144.548z"/>
<path android:fillColor="#FCAB29" android:pathData="M393.083,249.127c-65.571,0 -118.917,53.346 -118.917,118.917c0,65.57 53.346,118.916 118.917,118.916S512,433.614 512,368.044C512,302.473 458.654,249.127 393.083,249.127z"/>
<path android:fillColor="#DD8D19" android:pathData="M458.128,268.543c22.753,21.675 36.953,52.25 36.953,86.081c0,65.57 -53.346,118.916 -118.917,118.916c-23.991,0 -46.341,-7.148 -65.045,-19.417c21.347,20.336 50.223,32.836 81.964,32.836C458.654,486.96 512,433.614 512,368.044C512,326.464 490.544,289.807 458.128,268.543z"/>
<path android:fillColor="#F2DF33" android:pathData="M393.08,368.04m-80.17,0a80.17,80.17 0,1 1,160.34 0a80.17,80.17 0,1 1,-160.34 0"/>
<path android:fillColor="#FCAB29" android:pathData="M403.037,360.544h-19.908c-5.535,0 -10.038,-4.503 -10.038,-10.038s4.503,-10.038 10.038,-10.038h29.192c4.142,0 7.5,-3.357 7.5,-7.5s-3.358,-7.5 -7.5,-7.5h-11.738v-7.827c0,-4.143 -3.358,-7.5 -7.5,-7.5s-7.5,3.357 -7.5,7.5v7.827h-2.454c-13.806,0 -25.038,11.232 -25.038,25.038s11.232,25.038 25.038,25.038h19.908c5.535,0 10.038,4.503 10.038,10.037c0,5.535 -4.503,10.038 -10.038,10.038h-29.192c-4.142,0 -7.5,3.357 -7.5,7.5s3.358,7.5 7.5,7.5h11.739v7.827c0,4.143 3.358,7.5 7.5,7.5s7.5,-3.357 7.5,-7.5v-7.827h2.454c13.806,0 25.038,-11.232 25.038,-25.038S416.843,360.544 403.037,360.544z"/>
<path android:fillColor="#color/colorLightYellow" android:pathData="M368.669,144.262l-18.046,-14.437c-0.019,-0.016 -0.042,-0.025 -0.061,-0.041c-0.315,-0.248 -0.648,-0.473 -1.001,-0.668c-0.007,-0.003 -0.013,-0.008 -0.02,-0.012c-0.339,-0.186 -0.696,-0.339 -1.064,-0.472c-0.05,-0.018 -0.1,-0.038 -0.15,-0.055c-0.347,-0.116 -0.704,-0.207 -1.071,-0.272c-0.065,-0.011 -0.129,-0.02 -0.193,-0.029c-0.368,-0.056 -0.741,-0.093 -1.124,-0.093s-0.756,0.038 -1.124,0.093c-0.065,0.01 -0.129,0.018 -0.193,0.029c-0.367,0.065 -0.725,0.156 -1.071,0.272c-0.051,0.017 -0.1,0.037 -0.15,0.055c-0.368,0.132 -0.725,0.286 -1.064,0.472c-0.007,0.004 -0.013,0.009 -0.02,0.012c-0.353,0.195 -0.686,0.421 -1.001,0.668c-0.02,0.016 -0.042,0.025 -0.061,0.041l-18.046,14.437c-3.234,2.588 -3.759,7.307 -1.171,10.542c2.587,3.233 7.306,3.759 10.542,1.171l5.861,-4.688v68.76c0,4.143 3.358,7.5 7.5,7.5s7.5,-3.357 7.5,-7.5v-68.76l5.861,4.688c1.383,1.106 3.037,1.644 4.68,1.644c2.2,0 4.38,-0.963 5.861,-2.814C372.429,151.568 371.904,146.85 368.669,144.262z"/>
<path android:fillColor="#color/colorLightYellow" android:pathData="M462.959,104.039l-18.046,-14.437c-0.019,-0.016 -0.042,-0.025 -0.061,-0.041c-0.315,-0.248 -0.648,-0.473 -1.001,-0.668c-0.007,-0.003 -0.013,-0.008 -0.02,-0.012c-0.339,-0.186 -0.696,-0.339 -1.064,-0.472c-0.05,-0.018 -0.1,-0.038 -0.15,-0.055c-0.347,-0.116 -0.704,-0.207 -1.071,-0.272c-0.065,-0.011 -0.129,-0.02 -0.193,-0.029c-0.368,-0.056 -0.741,-0.093 -1.124,-0.093s-0.756,0.038 -1.124,0.093c-0.065,0.01 -0.129,0.018 -0.193,0.029c-0.367,0.065 -0.725,0.156 -1.071,0.272c-0.051,0.017 -0.1,0.037 -0.15,0.055c-0.368,0.132 -0.725,0.286 -1.064,0.472c-0.007,0.004 -0.013,0.009 -0.02,0.012c-0.353,0.195 -0.686,0.421 -1.001,0.668c-0.02,0.016 -0.042,0.025 -0.061,0.041l-18.046,14.437c-3.234,2.588 -3.759,7.307 -1.171,10.542c2.587,3.233 7.306,3.758 10.542,1.171l5.861,-4.688v68.76c0,4.143 3.358,7.5 7.5,7.5s7.5,-3.357 7.5,-7.5v-68.76l5.861,4.688c1.383,1.106 3.037,1.644 4.68,1.644c2.2,0 4.38,-0.963 5.861,-2.814C466.718,111.346 466.193,106.627 462.959,104.039z"/>
</vector>
than this website shows me this:
but my actual vector is this:
The website doesn't show the knapsack and those 2 arrows and after exporting also, it only shows the coins only.
I need to make this vector into PNG, that why I am trying it to make SVG then PNG, and I tried few more websites but either those shows deprecated.
I have converted it without of any programm. Here is the SVG for you:
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="80" viewBox="0 0 512 512">
<path fill="#fcab29" d="M150.561,144.549c-1.315,0 -2.647,-0.341 -3.86,-1.06L52.164,87.532c-3.609,-2.136 -4.803,-6.793 -2.667,-10.402c2.137,-3.608 6.793,-4.802 10.402,-2.667l94.537,55.957c3.609,2.136 4.803,6.793 2.667,10.402C155.685,143.217 153.156,144.549 150.561,144.549z"/>
<path fill="#fcab29" d="M150.568,144.548H47.842c-4.194,0 -7.593,-3.399 -7.593,-7.593s3.4,-7.593 7.593,-7.593h102.727c4.194,0 7.593,3.399 7.593,7.593S154.762,144.548 150.568,144.548z"/>
<path fill="#ed664c" d="M342.693,335.833L207.961,136.955l51.811,-74.838c10.849,-15.671 -0.367,-37.077 -19.426,-37.077H118.183c-19.059,0 -30.275,21.406 -19.426,37.077l51.811,74.838L15.836,335.833C5.516,351.066 0,369.043 0,387.443l0,0c0,50.82 41.198,92.018 92.017,92.018h174.495c50.82,0 92.017,-41.198 92.017,-92.018l0,0C358.529,369.043 353.013,351.066 342.693,335.833z"/>
<path fill="#ed664c" d="M342.693,335.833L207.961,136.955l51.811,-74.838c10.849,-15.671 -0.367,-37.077 -19.426,-37.077h-22.144c17.303,0 27.486,21.406 17.637,37.077l-47.038,74.838L311.12,335.833c9.369,15.233 14.377,33.211 14.377,51.61c0,50.82 -37.402,92.018 -83.539,92.018h24.555c50.82,0 92.017,-41.198 92.017,-92.018C358.529,369.043 353.013,351.066 342.693,335.833z"/>
<path fill="#fcab29" d="M214.129,144.548h-71.883c-4.194,0 -7.593,-3.399 -7.593,-7.593s3.4,-7.593 7.593,-7.593h71.883c4.194,0 7.593,3.399 7.593,7.593S218.323,144.548 214.129,144.548z"/>
<path fill="#FCAB29" d="M393.083,249.127c-65.571,0 -118.917,53.346 -118.917,118.917c0,65.57 53.346,118.916 118.917,118.916S512,433.614 512,368.044C512,302.473 458.654,249.127 393.083,249.127z"/>
<path fill="#DD8D19" d="M458.128,268.543c22.753,21.675 36.953,52.25 36.953,86.081c0,65.57 -53.346,118.916 -118.917,118.916c-23.991,0 -46.341,-7.148 -65.045,-19.417c21.347,20.336 50.223,32.836 81.964,32.836C458.654,486.96 512,433.614 512,368.044C512,326.464 490.544,289.807 458.128,268.543z"/>
<path fill="#F2DF33" d="M393.08,368.04m-80.17,0a80.17,80.17 0,1 1,160.34 0a80.17,80.17 0,1 1,-160.34 0"/>
<path fill="#FCAB29" d="M403.037,360.544h-19.908c-5.535,0 -10.038,-4.503 -10.038,-10.038s4.503,-10.038 10.038,-10.038h29.192c4.142,0 7.5,-3.357 7.5,-7.5s-3.358,-7.5 -7.5,-7.5h-11.738v-7.827c0,-4.143 -3.358,-7.5 -7.5,-7.5s-7.5,3.357 -7.5,7.5v7.827h-2.454c-13.806,0 -25.038,11.232 -25.038,25.038s11.232,25.038 25.038,25.038h19.908c5.535,0 10.038,4.503 10.038,10.037c0,5.535 -4.503,10.038 -10.038,10.038h-29.192c-4.142,0 -7.5,3.357 -7.5,7.5s3.358,7.5 7.5,7.5h11.739v7.827c0,4.143 3.358,7.5 7.5,7.5s7.5,-3.357 7.5,-7.5v-7.827h2.454c13.806,0 25.038,-11.232 25.038,-25.038S416.843,360.544 403.037,360.544z"/>
<path fill="#fcab29" d="M368.669,144.262l-18.046,-14.437c-0.019,-0.016 -0.042,-0.025 -0.061,-0.041c-0.315,-0.248 -0.648,-0.473 -1.001,-0.668c-0.007,-0.003 -0.013,-0.008 -0.02,-0.012c-0.339,-0.186 -0.696,-0.339 -1.064,-0.472c-0.05,-0.018 -0.1,-0.038 -0.15,-0.055c-0.347,-0.116 -0.704,-0.207 -1.071,-0.272c-0.065,-0.011 -0.129,-0.02 -0.193,-0.029c-0.368,-0.056 -0.741,-0.093 -1.124,-0.093s-0.756,0.038 -1.124,0.093c-0.065,0.01 -0.129,0.018 -0.193,0.029c-0.367,0.065 -0.725,0.156 -1.071,0.272c-0.051,0.017 -0.1,0.037 -0.15,0.055c-0.368,0.132 -0.725,0.286 -1.064,0.472c-0.007,0.004 -0.013,0.009 -0.02,0.012c-0.353,0.195 -0.686,0.421 -1.001,0.668c-0.02,0.016 -0.042,0.025 -0.061,0.041l-18.046,14.437c-3.234,2.588 -3.759,7.307 -1.171,10.542c2.587,3.233 7.306,3.759 10.542,1.171l5.861,-4.688v68.76c0,4.143 3.358,7.5 7.5,7.5s7.5,-3.357 7.5,-7.5v-68.76l5.861,4.688c1.383,1.106 3.037,1.644 4.68,1.644c2.2,0 4.38,-0.963 5.861,-2.814C372.429,151.568 371.904,146.85 368.669,144.262z"/>
<path fill="#fcab29" d="M462.959,104.039l-18.046,-14.437c-0.019,-0.016 -0.042,-0.025 -0.061,-0.041c-0.315,-0.248 -0.648,-0.473 -1.001,-0.668c-0.007,-0.003 -0.013,-0.008 -0.02,-0.012c-0.339,-0.186 -0.696,-0.339 -1.064,-0.472c-0.05,-0.018 -0.1,-0.038 -0.15,-0.055c-0.347,-0.116 -0.704,-0.207 -1.071,-0.272c-0.065,-0.011 -0.129,-0.02 -0.193,-0.029c-0.368,-0.056 -0.741,-0.093 -1.124,-0.093s-0.756,0.038 -1.124,0.093c-0.065,0.01 -0.129,0.018 -0.193,0.029c-0.367,0.065 -0.725,0.156 -1.071,0.272c-0.051,0.017 -0.1,0.037 -0.15,0.055c-0.368,0.132 -0.725,0.286 -1.064,0.472c-0.007,0.004 -0.013,0.009 -0.02,0.012c-0.353,0.195 -0.686,0.421 -1.001,0.668c-0.02,0.016 -0.042,0.025 -0.061,0.041l-18.046,14.437c-3.234,2.588 -3.759,7.307 -1.171,10.542c2.587,3.233 7.306,3.758 10.542,1.171l5.861,-4.688v68.76c0,4.143 3.358,7.5 7.5,7.5s7.5,-3.357 7.5,-7.5v-68.76l5.861,4.688c1.383,1.106 3.037,1.644 4.68,1.644c2.2,0 4.38,-0.963 5.861,-2.814C466.718,111.346 466.193,106.627 462.959,104.039z"/>
</svg>
I can say also why you had bad luck on the converting site:
https://shapeshifter.design
It is because you have in your code not convertable color values like #color/colorLightYellow. If you change android:fillColor="#color/colorLightYellow" to android:fillColor="#fcab29" and android:fillColor="#color/colorLightOrange" to android:fillColor="#ed664c" overall in your code then you will be able to convert your Android vector drawable image into SVG on this site without any mistakes.
You can use the https://shapeshifter.design/
Import the vector and use export button
Someone created this https://vd.floo.app/ - very simple and easy to use, but I think that problem is caused by usage of Android resource link #color/colorLightYellow, bcz none of converters know about what the color it is)
Related
I tried making background using coral draw or photoshop but its not working properly.
How should I draw the shape like this? Don't expect complete code, just give me idea or point me in the right direction.
making rectangle is easy with shape but how to add that bottom right side small rectangle and make them in one shape and also it i want to make it nine patch image because different screen size issue.
Try this .. I used https://www.autotracer.org/ to convert png to svg, then https://svg2vector.com/ to convert the svg to vector.
I would suggest make the burger image as an image background for a CardView with rounded corners and use ConstraintLayout to line up the Tab Badge drawable and the TextView
Bottom Tab Badge Drawable
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
android:viewportWidth="129"
android:viewportHeight="45"
android:width="129dp"
android:height="45dp">
<path
android:pathData="M0 0L0 44L7 44L9 44L10 44L12 44L13 43.9722L14 43.8889L15.9722 43.2778L17.75 41.8889L19.0833 40L19.9722 38L20.5833 36L21 34L21.3889 32L21.8611 30L22.1389 29L22.3611 28L22.6389 27L22.8611 26L23.4722 24L24.5 22L25.25 21.0278L26.0833 20.1111L27.0278 19.3056L29 18.1111L30 17.7222L31 17.4167L33 17.0833L34 17.0278L35 17L37 17L38 17L41 17L50 17L82 17L93 17L96 17L98 17L100 17.0833L101 17.25L102 17.5L103 17.9444L104.917 19.25L106.5 21.0278L107.528 23L108.139 25L108.361 26L108.611 27L108.944 29L109.056 30L109.389 32L109.611 33L110 35L110.417 37L110.694 38L111.417 40L112.5 41.8889L114.083 43.2778L116 43.8889L118 44L119 44L120 44L122 44L129 44L129 0L0 0z"
android:fillColor="#00FFFFFF" />
<path
android:pathData="M30 17L30.7778 17.7222L31.3056 17.75L32.1111 17.9444L33.0278 17.9722L35 18L36 18L38 18L51 18L101 18L100.222 17.2778L99.6944 17.25L98.8889 17.0556L97.9722 17.0278L96 17L95 17L93 17L80 17L30 17z"
android:fillColor="#00FFFFFF" />
<path
android:pathData="M101.667 17.3333L102 17.6667L102.333 17.6667L102.333 17.3333L101.667 17.3333z"
android:fillColor="#00FFFFFF" />
<path
android:pathData="M26 19L26.7778 19.6389L27.25 19.5278L28.0556 19.5278L30 19L29.2222 18.3056L28.75 18.3056L27.4722 18.3056L26 19z"
android:fillColor="#00FFFFFF" />
<path
android:pathData="M17 45L113 45L112.306 43.5L111.944 42.9444L110.917 41L110.472 40L110.167 39L109.639 37L109.389 36L109.194 35L108.806 33L108.611 32L108.389 31L108.056 29L107.944 28L107.583 26L107.306 25L106.583 23L106.083 22L104.75 20.1111L103.917 19.3333L102 18.3333L101 18.1111L100 18.0278L99 18L97 18L96 18L93 18L86 18L44 18L39 18L37 18L36 18L34 18L33 18.0278L32 18.0833L30 18.4722L28.0833 19.2778L27.25 19.8611L26.4722 20.4722L25.2778 22.0833L24.3889 24L24.0278 25L23.3889 27L23.1389 28L22.8611 29L22.3889 31L22.1944 32L22 33L21.5833 35L21 37L20.6667 38L19.8889 40L18.8056 41.9444L18.1944 42.9444L17.75 43.5L17 45z"
android:fillColor="#FFFFFF" />
<path
android:pathData="M103 18L103.75 19.5L104.222 20.0556L105.528 22L106.056 22.9444L106.722 24.5L107 26L107.722 25.2222L107.722 24.6944L107.861 23.8889L107.5 22L106.5 20.1111L105.806 19.3333L104.472 18.3611L103 18M25 20L24.0278 21.5L23.4444 23.0556L23.0833 24.9444L23 27L23.8056 26.2222L24 25.6944L24.4167 24.8889L25.1389 23.0278L25.4722 22.1111L25.5 21.3056L25.6389 20.7778L25 20M108 26L108 32L108.722 31.2222L108.75 30.6944L108.944 29.8889L108.944 28.1111L108.75 27.3056L108.722 26.7778L108 26M22 27L22 31L22.7222 30.2222L22.8889 29L22.7222 28.2778L22.7222 27.7778L22 27M21 31L21 36L21.7222 35.2222L21.75 34.6944L21.9167 33.0833L21.75 32.3056L21.7222 31.7778L21 31M109 32L109 37L109.722 36.2222L109.75 35.6944L109.917 34.0833L109.75 33.3056L109.722 32.7778L109 32M20 36L20 39L20.6944 38.25L20.6944 37.1944L20.6944 36.75L20 36M110 37L110.028 38.5L110.25 40.0556L110.5 41L110.944 41.9722L111.5 42.8889L113.083 44.2778L115 44.8889L117 45L118 45L119 45L122 45L129 45L128.222 44.2778L127.694 44.25L126.889 44.0556L125 44L124 44L121 44L120 44L118 43.9722L117 43.8889L116 43.6667L115.028 43.2778L114.083 42.6667L112.5 40.9722L111.444 39.1111L111 38.3056L110.806 37.7778L110 37M19 39L18.2222 40.5L17.6944 41.0278L16.8889 41.9444L15 43.2778L13 43.8889L12 43.9722L11 44L9 44L8 44L6 44L0 44L0.777778 44.7222L1.30556 44.75L2.11111 44.9444L3.02778 44.9722L5 45L7 45L10 45L11 45L13 45L14 44.9722L16 44.6667L17.8889 43.6667L18.6667 42.8889L19.25 42L19.6111 41.1111L19.6944 39.7778L19 39z"
android:fillColor="#00FFFFFF" />
I have an animated .SVG that animates perfectly in the browser, but when I import it into Andoroid Studio via the Vector Asset Studio, it turns it into a flat, monochrome image that doesn't animate. How do I keep Android Studio from breaking the file?
Here is the .xml file it converts it to:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp"
android:height="200dp"
android:viewportWidth="100"
android:viewportHeight="100">
<path
android:pathData="M50,21.5L50,21.5A3,2.15 0,0 1,53 23.65L53,36.35A3,2.15 0,0 1,50 38.5L50,38.5A3,2.15 0,0 1,47 36.35L47,23.65A3,2.15 0,0 1,50 21.5z"
android:fillColor="#91979b"/>
<path
android:pathData="M66.752,26.943L66.752,26.943A2.15,3 126,0 1,67.915 30.446L60.45,40.72A2.15,3 126,0 1,56.76 40.696L56.76,40.696A2.15,3 126,0 1,55.596 37.194L63.061,26.919A2.15,3 126,0 1,66.752 26.943z"
android:fillColor="#91979b"/>
<path
android:pathData="M77.105,41.193L77.105,41.193A3,2.15 72,0 1,75.987 44.711L63.909,48.635A3,2.15 72,0 1,60.937 46.446L60.937,46.446A3,2.15 72,0 1,62.055 42.929L74.133,39.004A3,2.15 72,0 1,77.105 41.193z"
android:fillColor="#91979b"/>
<path
android:pathData="M77.105,58.807L77.105,58.807A3,2.15 108,0 1,74.133 60.996L62.055,57.071A3,2.15 108,0 1,60.937 53.554L60.937,53.554A3,2.15 108,0 1,63.909 51.365L75.987,55.289A3,2.15 108,0 1,77.105 58.807z"
android:fillColor="#91979b"/>
<path
android:pathData="M66.752,73.057L66.752,73.057A2.15,3 54,0 1,63.061 73.081L55.596,62.806A2.15,3 54,0 1,56.76 59.304L56.76,59.304A2.15,3 54,0 1,60.45 59.28L67.915,69.554A2.15,3 54,0 1,66.752 73.057z"
android:fillColor="#91979b"/>
<path
android:pathData="M50,78.5L50,78.5A2.15,3 90,0 1,47 76.35L47,63.65A2.15,3 90,0 1,50 61.5L50,61.5A2.15,3 90,0 1,53 63.65L53,76.35A2.15,3 90,0 1,50 78.5z"
android:fillColor="#91979b"/>
<path
android:pathData="M33.248,73.057L33.248,73.057A2.15,3 126,0 1,32.085 69.554L39.55,59.28A2.15,3 126,0 1,43.24 59.304L43.24,59.304A2.15,3 126,0 1,44.404 62.806L36.939,73.081A2.15,3 126,0 1,33.248 73.057z"
android:fillColor="#91979b"/>
<path
android:pathData="M22.895,58.807L22.895,58.807A3,2.15 72,0 1,24.013 55.289L36.091,51.365A3,2.15 72,0 1,39.063 53.554L39.063,53.554A3,2.15 72,0 1,37.945 57.071L25.867,60.996A3,2.15 72,0 1,22.895 58.807z"
android:fillColor="#91979b"/>
<path
android:pathData="M22.895,41.193L22.895,41.193A3,2.15 108,0 1,25.867 39.004L37.945,42.929A3,2.15 108,0 1,39.063 46.446L39.063,46.446A3,2.15 108,0 1,36.091 48.635L24.013,44.711A3,2.15 108,0 1,22.895 41.193z"
android:fillColor="#91979b"/>
<path
android:pathData="M33.248,26.943L33.248,26.943A2.15,3 54,0 1,36.939 26.919L44.404,37.194A2.15,3 54,0 1,43.24 40.696L43.24,40.696A2.15,3 54,0 1,39.55 40.72L32.085,30.446A2.15,3 54,0 1,33.248 26.943z"
android:fillColor="#91979b"/>
</vector>
If you'd use AnimatedSvgView, you'd only have to add these paths into a string-array.
Recently i started to create adaptive icons for android app
SVG File Import for ic_launcher_background.xml successfully, but for ic_launcher_foreground.xml am getting error below like this
ERROR # line 8: Unsupported color format "rgba(0,0,0,0)"
ERROR # line 9: is not supported
Note: i can't able to post the full code so i remove the path data
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<group>
<clip-path android:pathData="M0 0H108V108H0V0Z" />
<path
android:fillColor="#00000000"
android:pathData="M0 0H108V108H0V0Z" />
<group
android:translateX="54.5"
android:translateY="52.5">
<path
android:fillColor="#FFE600"
android:pathData="M-16.06429 -19.14453L-16.06429 -1.557617L-12.76498 -1.217773L-12.76498 0L-23.44173 0L-23.44173 -1.217773L-20.15658 -1.557617L-20.15658 -15.87354L-23.42757 -14.79736L-23.42757 -16.00098L-18.07504 -19.14453L-16.06429 -19.14453ZM2.131508 -9.572266L2.131508 -9.572266Q2.131508 0.2832031 -4.098961 0.2832031L-4.098961 0.2832031Q-7.100914 0.2832031 -8.630211 -2.237305Q-10.15951 -4.757813 -10.15951 -9.572266L-10.15951 -9.572266Q-10.15951 -14.2876 -8.630211 -16.78687Q-7.100914 -19.28613 -3.98568 -19.28613L-3.98568 -19.28613Q-0.9837266 -19.28613 0.5738906 -16.81519Q2.131508 -14.34424 2.131508 -9.572266ZM-2.017418 -9.572266L-2.017418 -9.572266Q-2.017418 -13.99023 -2.513023 -15.9231Q-3.008629 -17.85596 -4.070641 -17.85596L-4.070641 -17.85596Q-5.118492 -17.85596 -5.564537 -15.98682Q-6.010582 -14.11768 -6.010582 -9.572266L-6.010582 -9.572266Q-6.010582 -4.956055 -5.557457 -3.044434Q-5.104332 -1.132813 -4.070641 -1.132813L-4.070641 -1.132813Q-3.022789 -1.132813 -2.520104 -3.093994Q-2.017418 -5.055176 -2.017418 -9.572266ZM16.33414 -14.31592L16.33414 -14.31592Q16.33414 -12.7583 15.5695 -11.66089Q14.80485 -10.56348 13.41715 -10.06787L13.41715 -10.06787Q15.04557 -9.458984 15.90934 -8.18457Q16.77311 -6.910156 16.77311 -5.125977L16.77311 -5.125977Q16.77311 -2.435547 15.22257 -1.076172Q13.67204 0.2832031 10.40104 0.2832031L10.40104 0.2832031Q4.198891 0.2832031 4.198891 -5.125977L4.198891 -5.125977Q4.198891 -6.938477 5.07682 -8.212891Q5.95475 -9.487305 7.512367 -10.06787L7.512367 -10.06787Q6.138832 -10.5918 5.388344 -11.68213Q4.637855 -12.77246 4.637855 -14.3584L4.637855 -14.3584Q4.637855 -16.68066 6.174232 -17.9834Q7.710609 -19.28613 10.51432 -19.28613L10.51432 -19.28613Q13.26139 -19.28613 14.79777 -17.96216Q16.33414 -16.63818 16.33414 -14.31592ZM12.75163 -5.125977L12.75163 -5.125977Q12.75163 -7.306641 12.18522 -8.297852Q11.61881 -9.289063 10.40104 -9.289063L10.40104 -9.289063Q9.239906 -9.289063 8.730141 -8.326172Q8.220375 -7.363281 8.220375 -5.125977L8.220375 -5.125977Q8.220375 -2.931152 8.737221 -2.039063Q9.254066 -1.146973 10.40104 -1.146973L10.40104 -1.146973Q11.61881 -1.146973 12.18522 -2.081543Q12.75163 -3.016113 12.75163 -5.125977ZM12.31266 -14.31592L12.31266 -14.31592Q12.31266 -16.1709 11.84538 -17.01343Q11.37809 -17.85596 10.42936 -17.85596L10.42936 -17.85596Q9.523109 -17.85596 9.091225 -17.02051Q8.65934 -16.18506 8.65934 -14.31592L8.65934 -14.31592Q8.65934 -12.39014 9.084145 -11.59717Q9.508949 -10.8042 10.42936 -10.8042L10.42936 -10.8042Q11.40641 -10.8042 11.85954 -11.61841Q12.31266 -12.43262 12.31266 -14.31592Z"
android:strokeWidth="0.5"
android:strokeColor="#DC8B00" />
</group>
<group
android:translateX="54.5"
android:translateY="70.5">
<path
android:fillColor="#FFE600"
android:pathData="M-11.78146 -3.598633L-11.78146 -3.598633Q-11.78146 -5.15625 -12.3508 -5.884033Q-12.92014 -6.611816 -14.20383 -6.611816L-14.20383 -6.611816L-14.60129 -6.611816L-14.60129 -0.6123047Q-14.08566 -0.5693359 -13.66672 -0.5693359L-13.66672 -0.5693359Q-12.96848 -0.5693359 -12.56296 -0.8701172Q-12.15744 -1.170898 -11.96945 -1.812744Q-11.78146 -2.45459 -11.78146 -3.598633ZM-17.21164 -7.202637L-13.79025 -7.202637Q-11.85129 -7.202637 -10.92478 -6.324463Q-9.998262 -5.446289 -9.998262 -3.641602L-9.998262 -3.641602Q-9.998262 -1.788574 -10.88449 -0.8835449Q-11.77072 0.02148438 -13.56467 0.02148438L-13.56467 0.02148438L-15.97629 0L-17.21164 0L-17.21164 -0.3920898L-16.28781 -0.5371094L-16.28781 -6.670898L-17.21164 -6.810547L-17.21164 -7.202637ZM-7.119355 -7.632324L-7.119355 -5.446289Q-7.119355 -5.091797 -7.151582 -4.608398L-7.151582 -4.608398L-6.780977 -4.796387Q-6.018281 -5.183105 -5.411348 -5.183105L-5.411348 -5.183105Q-4.014863 -5.183105 -4.014863 -3.695313L-4.014863 -3.695313L-4.014863 -0.4833984L-3.50998 -0.3544922L-3.50998 0L-6.018281 0L-6.018281 -0.3544922L-5.567109 -0.4833984L-5.567109 -3.48584Q-5.567109 -3.937012 -5.757783 -4.189453Q-5.948457 -4.441895 -6.302949 -4.441895L-6.302949 -4.441895Q-6.711152 -4.441895 -7.119355 -4.259277L-7.119355 -4.259277L-7.119355 -0.4833984L-6.657441 -0.3544922L-6.657441 0L-9.165742 0L-9.165742 -0.3544922L-8.671602 -0.4833984L-8.671602 -7.148926L-9.187227 -7.277832L-9.187227 -7.632324L-7.119355 -7.632324ZM-1.00168 -5.048828L-1.00168 -0.4833984L-0.448457 -0.3544922L-0.448457 0L-3.101777 0L-3.101777 -0.3544922L-2.553926 -0.4833984L-2.553926 -4.56543L-3.069551 -4.694336L-3.069551 -5.048828L-1.00168 -5.048828ZM-2.607637 -6.810547L-2.607637 -6.810547Q-2.607637 -7.159668 -2.363252 -7.395996Q-2.118867 -7.632324 -1.780488 -7.632324L-1.780488 -7.632324Q-1.436738 -7.632324 -1.197725 -7.393311Q-0.9587109 -7.154297 -0.9587109 -6.810547L-0.9587109 -6.810547Q-0.9587109 -6.472168 -1.195039 -6.227783Q-1.431367 -5.983398 -1.780488 -5.983398L-1.780488 -5.983398Q-2.124238 -5.983398 -2.365938 -6.222412Q-2.607637 -6.461426 -2.607637 -6.810547ZM4.847441 -4.586914L2.82791 0.1074219L2.178008 0.1074219L0.06716797 -4.56543L-0.2873242 -4.694336L-0.2873242 -5.048828L2.296172 -5.048828L2.296172 -4.694336L1.694609 -4.554688L2.989043 -1.675781L4.15457 -4.56543L3.56375 -4.694336L3.56375 -5.048828L5.212676 -5.048828L5.212676 -4.694336L4.847441 -4.586914ZM7.694121 0.1557617L7.694121 0.1557617L5.67459 -4.56543L5.320098 -4.694336L5.320098 -5.048828L7.903594 -5.048828L7.903594 -4.694336L7.302031 -4.554688L8.489043 -1.761719L9.547148 -4.56543L8.956328 -4.694336L8.956328 -5.048828L10.60525 -5.048828L10.60525 -4.694336L10.24002 -4.586914L8.247344 0.3168945Q7.903594 1.192383 7.645781 1.587158Q7.387969 1.981934 7.07376 2.177979Q6.759551 2.374023 6.356719 2.374023L6.356719 2.374023Q5.92166 2.374023 5.470488 2.271973L5.470488 2.271973L5.470488 0.972168L5.792754 0.972168L6.023711 1.648926Q6.179473 1.772461 6.421172 1.772461L6.421172 1.772461Q6.625273 1.772461 6.781035 1.675781Q6.936797 1.579102 7.07376 1.396484Q7.210723 1.213867 7.334258 0.947998Q7.457793 0.6821289 7.694121 0.1557617ZM13.64529 -5.161621L13.64529 -5.161621Q15.54129 -5.161621 15.54129 -3.765137L15.54129 -3.765137L15.54129 -0.4833984L16.04617 -0.3544922L16.04617 0L14.18777 0L14.06961 -0.3867188Q13.65066 -0.1020508 13.31229 0.002685547Q12.97391 0.1074219 12.63016 0.1074219L12.63016 0.1074219Q11.06717 0.1074219 11.06717 -1.396484L11.06717 -1.396484Q11.06717 -1.96582 11.29812 -2.306885Q11.52908 -2.647949 11.96414 -2.811768Q12.3992 -2.975586 13.33377 -2.99707L13.33377 -2.99707L13.98904 -3.013184L13.98904 -3.749023Q13.98904 -4.662109 13.24246 -4.662109L13.24246 -4.662109Q12.79129 -4.662109 12.2327 -4.382813L12.2327 -4.382813L12.02859 -3.754395L11.6741 -3.754395L11.6741 -4.973633Q12.48514 -5.097168 12.86648 -5.129395Q13.24783 -5.161621 13.64529 -5.161621ZM13.98904 -0.7304688L13.98904 -2.535156L13.53787 -2.519043Q13.01687 -2.497559 12.81546 -2.245117Q12.61404 -1.992676 12.61404 -1.428711L12.61404 -1.428711Q12.61404 -0.972168 12.77518 -0.7573242Q12.93631 -0.5424805 13.19412 -0.5424805L13.19412 -0.5424805Q13.55936 -0.5424805 13.98904 -0.7304688L13.98904 -0.7304688Z"
android:strokeWidth="0.5"
android:strokeColor="#DC8B00" />
<path
android:fillColor="#FFE600"
android:pathData="M-14.81646 7.401367L-14.81646 7.401367Q-14.81646 5.84375 -15.3858 5.115967Q-15.95514 4.388184 -17.23883 4.388184L-17.23883 4.388184L-17.63629 4.388184L-17.63629 10.3877Q-17.12066 10.43066 -16.70172 10.43066L-16.70172 10.43066Q-16.00348 10.43066 -15.59796 10.12988Q-15.19244 9.829102 -15.00445 9.187256Q-14.81646 8.54541 -14.81646 7.401367ZM-20.24664 3.797363L-16.82525 3.797363Q-14.88629 3.797363 -13.95978 4.675537Q-13.03326 5.553711 -13.03326 7.358398L-13.03326 7.358398Q-13.03326 9.211426 -13.91949 10.11646Q-14.80572 11.02148 -16.59967 11.02148L-16.59967 11.02148L-19.01129 11L-20.24664 11L-20.24664 10.60791L-19.32281 10.46289L-19.32281 4.329102L-20.24664 4.189453L-20.24664 3.797363ZM-9.842832 5.827637L-9.842832 5.827637Q-8.816953 5.827637 -8.357725 6.375488Q-7.898496 6.92334 -7.898496 8.078125L-7.898496 8.078125L-7.898496 8.518555L-10.54645 8.518555L-10.54645 8.604492Q-10.54645 9.404785 -10.41754 9.743164Q-10.28863 10.08154 -9.998594 10.25879Q-9.708555 10.43604 -9.203672 10.43604L-9.203672 10.43604Q-8.731016 10.43604 -8.011289 10.28027L-8.011289 10.28027L-8.011289 10.69385Q-8.306699 10.87109 -8.77667 10.98657Q-9.246641 11.10205 -9.692441 11.10205L-9.692441 11.10205Q-10.93316 11.10205 -11.52667 10.45483Q-12.12018 9.807617 -12.12018 8.44873L-12.12018 8.44873Q-12.12018 7.127441 -11.55353 6.477539Q-10.98688 5.827637 -9.842832 5.827637ZM-9.901914 6.370117L-9.901914 6.370117Q-10.22418 6.370117 -10.38263 6.719238Q-10.54107 7.068359 -10.54107 7.95459L-10.54107 7.95459L-9.370176 7.95459Q-9.370176 7.234863 -9.418516 6.942139Q-9.466855 6.649414 -9.582334 6.509766Q-9.697813 6.370117 -9.901914 6.370117ZM-3.601621 9.399414L-3.601621 9.399414Q-3.601621 10.24268 -4.119932 10.67505Q-4.638242 11.10742 -5.626523 11.10742L-5.626523 11.10742Q-6.034727 11.10742 -6.526182 11.0188Q-7.017637 10.93018 -7.270078 10.8335L-7.270078 10.8335L-7.270078 9.458496L-6.915586 9.458496L-6.711484 10.16748Q-6.523496 10.35547 -6.217344 10.48169Q-5.911191 10.60791 -5.594297 10.60791L-5.594297 10.60791Q-5.127012 10.60791 -4.89874 10.40649Q-4.670469 10.20508 -4.670469 9.893555L-4.670469 9.893555Q-4.670469 9.598145 -4.890684 9.420898Q-5.110898 9.243652 -5.852109 9.012695L-5.852109 9.012695Q-6.630918 8.770996 -6.955869 8.352051Q-7.28082 7.933105 -7.28082 7.320801L-7.28082 7.320801Q-7.28082 6.633301 -6.770566 6.225098Q-6.260313 5.816895 -5.454648 5.816895L-5.454648 5.816895Q-4.901426 5.816895 -3.966855 5.972656L-3.966855 5.972656L-3.966855 7.26709L-4.321348 7.26709L-4.493223 6.67627Q-4.648984 6.520508 -4.930967 6.421143Q-5.212949 6.321777 -5.465391 6.321777L-5.465391 6.321777Q-5.852109 6.321777 -6.037412 6.480225Q-6.222715 6.638672 -6.222715 6.912598L-6.222715 6.912598Q-6.222715 7.197266 -5.991758 7.379883Q-5.760801 7.5625 -5.041074 7.777344L-5.041074 7.777344Q-4.256895 8.019043 -3.929258 8.413818Q-3.601621 8.808594 -3.601621 9.399414ZM-0.9912695 3.367676L-0.9912695 5.553711Q-0.9912695 5.908203 -1.023496 6.391602L-1.023496 6.391602L-0.6528906 6.203613Q0.1098047 5.816895 0.7167383 5.816895L0.7167383 5.816895Q2.113223 5.816895 2.113223 7.304688L2.113223 7.304688L2.113223 10.5166L2.618105 10.64551L2.618105 11L0.1098047 11L0.1098047 10.64551L0.5609766 10.5166L0.5609766 7.51416Q0.5609766 7.062988 0.3703027 6.810547Q0.1796289 6.558105 -0.1748633 6.558105L-0.1748633 6.558105Q-0.5830664 6.558105 -0.9912695 6.740723L-0.9912695 6.740723L-0.9912695 10.5166L-0.5293555 10.64551L-0.5293555 11L-3.037656 11L-3.037656 10.64551L-2.543516 10.5166L-2.543516 3.851074L-3.059141 3.722168L-3.059141 3.367676L-0.9912695 3.367676ZM5.717227 5.838379L5.717227 5.838379Q7.613223 5.838379 7.613223 7.234863L7.613223 7.234863L7.613223 10.5166L8.118105 10.64551L8.118105 11L6.259707 11L6.141543 10.61328Q5.722598 10.89795 5.384219 11.00269Q5.04584 11.10742 4.70209 11.10742L4.70209 11.10742Q3.139102 11.10742 3.139102 9.603516L3.139102 9.603516Q3.139102 9.03418 3.370059 8.693115Q3.601016 8.352051 4.036074 8.188232Q4.471133 8.024414 5.405703 8.00293L5.405703 8.00293L6.060977 7.986816L6.060977 7.250977Q6.060977 6.337891 5.314395 6.337891L5.314395 6.337891Q4.863223 6.337891 4.304629 6.617188L4.304629 6.617188L4.100527 7.245605L3.746035 7.245605L3.746035 6.026367Q4.55707 5.902832 4.938418 5.870605Q5.319766 5.838379 5.717227 5.838379ZM6.060977 10.26953L6.060977 8.464844L5.609805 8.480957Q5.088809 8.502441 4.887393 8.754883Q4.685977 9.007324 4.685977 9.571289L4.685977 9.571289Q4.685977 10.02783 4.847109 10.24268Q5.008242 10.45752 5.266055 10.45752L5.266055 10.45752Q5.631289 10.45752 6.060977 10.26953L6.060977 10.26953ZM10.54047 5.951172L10.61566 6.391602L10.9809 6.203613Q11.73285 5.816895 12.32904 5.816895L12.32904 5.816895Q13.23139 5.816895 13.53217 6.472168L13.53217 6.472168Q14.63324 5.816895 15.39057 5.816895L15.39057 5.816895Q16.75482 5.816895 16.75482 7.304688L16.75482 7.304688L16.75482 10.5166L17.25971 10.64551L17.25971 11L14.75141 11L14.75141 10.64551L15.20258 10.5166L15.20258 7.51416Q15.20258 7.062988 15.02802 6.810547Q14.85346 6.558105 14.49896 6.558105L14.49896 6.558105Q14.1015 6.558105 13.63959 6.783691L13.63959 6.783691Q13.6933 7.009277 13.6933 7.304688L13.6933 7.304688L13.6933 10.5166L14.19818 10.64551L14.19818 11L11.68988 11L11.68988 10.64551L12.14105 10.5166L12.14105 7.51416Q12.14105 7.062988 11.96649 6.810547Q11.79193 6.558105 11.43744 6.558105L11.43744 6.558105Q11.08295 6.558105 10.62641 6.767578L10.62641 6.767578L10.62641 10.5166L11.08832 10.64551L11.08832 11L8.58002 11L8.58002 10.64551L9.07416 10.5166L9.07416 6.43457L8.58002 6.305664L8.58002 5.951172L10.54047 5.951172Z"
android:strokeWidth="0.5"
android:strokeColor="#DC8B00" />
</group>
</group>
</vector>
Solution is you need to fix your SVG first.
Very easy like this:
fill="#186bfe" fill-opacity="0.3"
Your case rgba(0,0,0,0). then it should be fixed
fill="#000000" fill-opacity="0"
I'm trying to assert whether the correct image is displayed on an image view in Android using Espresso. The images were provided as SVG and converted to vector drawable directly using Android Studio converter. My custom matcher has successful tests for some of the images but not for other ones. If I swap the SVG XML files then the results get inverted with the ones who failed succeeding now which makes me suspect it could be something to do with checking the SVG itself maybe due to the amount of characters for some of the path as when I delete some lines that contain more characters than the other ones it works but not really sure how to properly fix that.
This is the SVG that works
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="80dp"
android:height="80dp"
android:viewportWidth="80"
android:viewportHeight="80">
<path
android:pathData="M37.2,37.1m-34.85,0a34.85,34.85 0,1 1,69.7 0a34.85,34.85 0,1 1,-69.7 0"
android:fillColor="#fff"/>
<path
android:pathData="M49.22,19.23h2.67A4.79,4.79 0,0 1,56.67 24V53.39a4.79,4.79 0,0 1,-4.78 4.77H22.51a4.79,4.79 0,0 1,-4.78 -4.77V24a4.79,4.79 0,0 1,4.78 -4.77h3.2"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M45.37,24.93a8.9,8.9 0,1 1,-8.9 -8.9A8.9,8.9 0,0 1,45.37 24.93Z"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M35.88,25.46L40.08,21.72"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
</vector>
But this is the SVG that doesn't work
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="80dp"
android:height="80dp"
android:viewportWidth="80"
android:viewportHeight="80">
<path
android:pathData="M37.12,37.28m-34.85,0a34.85,34.85 0,1 1,69.7 0a34.85,34.85 0,1 1,-69.7 0"
android:fillColor="#fff"/>
<path
android:pathData="M34.37,44.93h8.46a3,3 0,0 0,3 -3h0a3,3 0,0 0,-3 -3H34.37"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M34.37,51h8.46a3,3 0,0 0,3 -3h0a3,3 0,0 0,-3 -3H34.37"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M28.6,57H27.54A16.27,16.27 0,0 1,19.62 55h0"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M34.37,51H41.1a3,3 0,0 1,3 3h0a3,3 0,0 1,-3 3H34.37"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M47.31,38.87h8a3.09,3.09 0,0 0,3.11 -2.81,3 3,0 0,0 -0.88,-2.36 3,3 0,0 0,-2.14 -0.89H30.84A1.06,1.06 0,0 1,30.09 31l6.07,-6.07a3.09,3.09 0,0 0,0.19 -4.21,3 3,0 0,0 -4.41,-0.13L18.19,34.33c-6.2,6.21 -6.43,16 1.43,20.65"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M54.91,43.54s3.42,4 3.42,7.05a3.42,3.42 0,0 1,-6.84 0c0,-3 3.42,-7.05 3.42,-7.05"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M54.8,48.13a5.3,5.3 0,0 0,-0.52 2,1.79 1.79,0 0,0 0.79,1.5"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M54.91,35.39L54.91,35.84"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M54.91,25.3L54.91,29.03"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M34.37,51a3,3 0,0 1,-3 -3h0a3,3 0,0 1,3 -3"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M34.37,57a3,3 0,0 1,-3 -3h0a3,3 0,0 1,3 -3"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M34.37,44.93a3,3 0,0 1,-3 -3h0a3,3 0,0 1,3 -3"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
<path
android:pathData="M58.13,18.56v4.6A2.14,2.14 0,0 1,56 25.3H53.83a2.14,2.14 0,0 1,-2.14 -2.14v-4.6"
android:strokeWidth="1.97"
android:fillColor="#00000000"
android:strokeColor="#89d3dd"
android:strokeLineCap="round"/>
</vector>
This is my custom matcher
public class EspressoTestsMatchers {
public Matcher<View> withDrawable(final int resourceId) {
return new DrawableMatcher(resourceId);
}
public Matcher<View> noDrawable() {
return new DrawableMatcher(-1);
}
}
public class DrawableMatcher extends TypeSafeMatcher<View> {
private final int expectedId;
public DrawableMatcher(int resourceId) {
super(View.class);
this.expectedId = resourceId;
}
#Override
protected boolean matchesSafely(View target) {
if (!(target instanceof ImageView)) {
return false;
}
ImageView imageView = (ImageView) target;
if (expectedId < 0) {
return imageView.getDrawable() == null;
}
Resources resources = target.getContext().getResources();
Drawable expectedDrawable = resources.getDrawable(expectedId);
if (expectedDrawable == null) {
return false;
}
Bitmap bitmap = getBitmap(imageView.getDrawable());
Bitmap otherBitmap = getBitmap(expectedDrawable);
return bitmap.sameAs(otherBitmap);
}
private Bitmap getBitmap(Drawable drawable) {
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
#Override
public void describeTo(Description description) {
}
}
Called this way
onView(withId(R.id.rv_metrics)).perform(actionOnItemAtPosition(0, click()));
onView(withId(R.id.iv_type)).check(matches(new EspressoTestsMatchers().withDrawable(R.drawable.ic_metrics_dialog_weight)));
Thanks very much.
Update
Tried also to convert the SVG to Bitmap instead and do the assertion only then but for some reason getting the item drawable still doesn't make the assertion pass.
BackgroundDrawableMatcher2(Drawable expectedDrawable) {
super(View.class);
mExpectedDrawable = expectedDrawable;
}
#Override
protected boolean matchesSafely(View item) {
Drawable drawable = ContextCompat.getDrawable(getTargetContext(), R.drawable.ic_metrics_dialog_weight); // Hardcoding this makes the assertion work
ImageView imageView = (ImageView) item;
return getBitmap2(imageView.getDrawable()).sameAs(getBitmap2(mExpectedDrawable)); // Getting the item this way instead doesn't though :(
}
These are the lines that need to be commented out to make my test pass
For some reason changing the code from setImageDrawable(AppCompatResources) to setImageResource has solved the issue.
//ivDialogType.setImageDrawable(AppCompatResources.getDrawable(Objects.requireNonNull(getContext()), R.drawable.ic_metrics_dialog_weight));
ivDialogType.setImageResource(R.drawable.ic_metrics_dialog_weight);
Alternatively setting a tag for the image may be a good option as well as of this SO question.
In my android app I try to get a Bitmap-Object from a SVG-File and store it in the cache. Then it should be displayed from this bitmap in an ImageView Object. I don't get it working, either the ImageView gets a wrong density, the Picture is too small or too large. May anybody tell me whats wrong with that code? For my purposes I use the AndroidSVG library (link). The Image should has 30dp width and height.
ImageView img = (ImageView)getView().findViewById(R.id.testingImage);
try {
int size = convertDPtoPixels(30);
SVG svg = SVG.getFromResource(mGlob.mContext,R.raw.vectorimage);
svg.setDocumentHeight(size);
svg.setDocumentWidth(size);
PictureDrawable pictureDrawable = new PictureDrawable(svg.renderToPicture());
Bitmap mutableBitmap = Bitmap.createBitmap(30, 30, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mutableBitmap);
pictureDrawable.setBounds(0,0,size,size);
pictureDrawable.draw(canvas);
img.setImageBitmap(mutableBitmap);
} catch (SVGParseException e) {
e.printStackTrace();
}
Edit 30.3.2015
If I try to create the Bitmap with the Pixel-size like this, I get a too small Image (but it is sharp):
Bitmap mutableBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Addition Information:
The Blue Color is the background color, from my ImageView. I use it to see where it starts and end, because my SVG has transparent surfaces. The SVG should fill the blue area...
Here is my SVG-File:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="30"
height="30"
id="svg15733"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="vectorimage.svg">
<defs
id="defs15735" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="9.1"
inkscape:cx="21.063016"
inkscape:cy="17.702822"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1366"
inkscape:window-height="715"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
borderlayer="true"
inkscape:showpageshadow="false" />
<metadata
id="metadata15738">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-1022.3622)">
<path
style="fill:#ffe71d;fill-opacity:1;stroke:#000000;stroke-width:0.3515625;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
d="m 20.507812,1023.827 8.027344,8.0274 0,11.4258 -8.027344,7.6172 -11.4257807,0 -7.6171876,-7.6172 0,-11.4258 7.6171876,-8.0274 z"
id="Auswahl"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccc" />
<flowRoot
xml:space="preserve"
id="flowRoot16280"
style="font-style:normal;font-weight:normal;font-size:72px;line-height:125%;font-family:Sans;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"><flowRegion
id="flowRegion16282"><rect
id="rect16284"
width="123.23861"
height="98.994949"
x="171.72594"
y="179.65981" /></flowRegion><flowPara
id="flowPara16286" /></flowRoot> <text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:4.21875px;line-height:125%;font-family:Sans;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
x="6.8066916"
y="1049.5211"
id="text16288"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan16290"
x="6.8066916"
y="1049.5211"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:31.46484184px;font-family:Tahoma;-inkscape-font-specification:'Tahoma Bold'">?</tspan></text>
<path
transform="translate(0,540.3622)"
style="display:inline;fill:#000000;fill-opacity:0.09958508;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 9.0820313,483.46484 -4.048462,4.26636 21.1303707,17.43713 2.371216,-2.25036 0,-11.42578 -8.027344,-8.02735 -11.4257807,0 z"
id="path16293"
inkscape:connector-curvature="0" />
<path
transform="translate(0,540.3622)"
style="display:inline;fill:#000000;fill-opacity:0.06639003;stroke:none;stroke-width:6;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
d="m 9.0820313,483.46484 -7.6171876,8.02735 0,7.68493 25.0598143,-9.69543 -6.016846,-6.01685 -11.4257807,0 z"
id="path16295"
inkscape:connector-curvature="0" />
</g>
</svg>
You appear to be rendering the SVG to a 30x30 bitmap then scaling it up to (size x size).
Try changing the bitmap creation to:
Bitmap mutableBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Update:
The problem is that Inkscape doesn't automatically give it's SVG files a viewBox.
Read this AndroidSVG FAQ question on how to deal with Inkscape files. https://code.google.com/p/androidsvg/wiki/FAQ#Dealing_with_Inkscape_files
You can either follow the advice there (which updates the SVG programmatically at runtime). Or alternatively, alter the SVG by hand. Make the following changes:
width="100%"
height="100%"
viewBox="0 0 30 30"
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="100%"
height="100%"
id="svg15733"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="vectorimage.svg"
viewBox="0 0 30 30">
<defs
id="defs15735" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="9.1"
inkscape:cx="21.063016"
inkscape:cy="17.702822"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1366"
inkscape:window-height="715"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
borderlayer="true"
inkscape:showpageshadow="false" />
<metadata
id="metadata15738">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Ebene 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-1022.3622)">
<path
style="fill:#ffe71d;fill-opacity:1;stroke:#000000;stroke-width:0.3515625;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
d="m 20.507812,1023.827 8.027344,8.0274 0,11.4258 -8.027344,7.6172 -11.4257807,0 -7.6171876,-7.6172 0,-11.4258 7.6171876,-8.0274 z"
id="Auswahl"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccc" />
<flowRoot
xml:space="preserve"
id="flowRoot16280"
style="font-style:normal;font-weight:normal;font-size:72px;line-height:125%;font-family:Sans;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"><flowRegion
id="flowRegion16282"><rect
id="rect16284"
width="123.23861"
height="98.994949"
x="171.72594"
y="179.65981" /></flowRegion><flowPara
id="flowPara16286" /></flowRoot> <text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:4.21875px;line-height:125%;font-family:Sans;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"
x="6.8066916"
y="1049.5211"
id="text16288"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan16290"
x="6.8066916"
y="1049.5211"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:31.46484184px;font-family:Tahoma;-inkscape-font-specification:'Tahoma Bold'">?</tspan></text>
<path
transform="translate(0,540.3622)"
style="display:inline;fill:#000000;fill-opacity:0.09958508;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 9.0820313,483.46484 -4.048462,4.26636 21.1303707,17.43713 2.371216,-2.25036 0,-11.42578 -8.027344,-8.02735 -11.4257807,0 z"
id="path16293"
inkscape:connector-curvature="0" />
<path
transform="translate(0,540.3622)"
style="display:inline;fill:#000000;fill-opacity:0.06639003;stroke:none;stroke-width:6;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
d="m 9.0820313,483.46484 -7.6171876,8.02735 0,7.68493 25.0598143,-9.69543 -6.016846,-6.01685 -11.4257807,0 z"
id="path16295"
inkscape:connector-curvature="0" />
</g>
</svg>