I have one vector drawable image of EYE and i want round shape border around that but i cant found any solution.
My requirement for image is like:here is my requirement image!
i am using xml code for eye icon as below:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="26.012dp"
android:height="16dp"
android:viewportWidth="26.012"
android:viewportHeight="16">
<path
android:fillColor="#FF000000"
android:pathData="M13.012,5.518a3.606,3.606 0,0 1,1.312 0.246,2.168 2.168,0 0,0 2.293,3.671 3.617,3.617 0,1 1,-3.6 -3.917Z"
android:fillType="evenOdd"/>
<path
android:fillColor="#FF000000"
android:pathData="M13.006,16c4.959,0 10.714,-3.655 12.552,-7.074 -2.7,0.038 -4.571,-1.213 -6.415,-2.414a5.237,5.237 0,0 1,0.659 2.536c0,3.252 -3.034,5.889 -6.777,5.889s-6.777,-2.637 -6.777,-5.889a5.235,5.235 0,0 1,0.681 -2.574c-1.864,1.212 -3.744,2.491 -6.474,2.452 1.837,3.418 7.593,7.074 12.552,7.074ZM13.006,3.149c-4.309,0 -7.693,4 -10.737,5.023 -0.585,0.2 -1.7,0.4 -2.131,0.02 -0.316,-0.278 -0.1,-0.274 0.792,-1.1 3.467,-3.192 6.4,-7.08 12.016,-7.1 5.776,-0.017 8.581,3.823 12.137,7.1 0.893,0.822 1.108,0.817 0.792,1.1 -0.433,0.38 -1.546,0.177 -2.131,-0.02C20.699,7.147 17.315,3.149 13.006,3.149Z"
android:fillType="evenOdd"/>
</vector>
now I want to add border arround this image as per above image.
help me if any one is having understanding of this stuff.
Thank you in advance!!
You can modify your SVG
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="125dp"
android:height="125dp"
android:viewportWidth="125"
android:viewportHeight="125">
<path
android:pathData="M48.7,11.5c-12,3.3 -24.1,12.2 -30.8,22.6 -13.8,21.5 -10.9,49.1 7,66.9 21.7,21.6 54.5,21.6 76.2,-0 29,-28.8 15.4,-79 -24.2,-89.5 -6.6,-1.8 -21.7,-1.8 -28.2,-0zM73.2,13.1c8.9,1.8 19,7.3 25.5,13.8 10.1,10.1 15.3,22.5 15.3,36.6 0,14.7 -5.2,26.7 -15.9,36.8 -7.6,7.1 -15.3,11.2 -24.9,13.3 -8.4,1.7 -12,1.7 -20.4,-0 -9.6,-2.1 -17.3,-6.2 -24.9,-13.3 -10.7,-10.1 -15.9,-22.1 -15.9,-36.8 0,-32.4 29.8,-56.9 61.2,-50.4z"
android:fillColor="#000000"
android:strokeColor="#00000000"/>
<path
android:pathData="M51.8,41.5c-5.5,2.1 -11.6,6.5 -20.5,14.9l-7.8,7.5 3.3,0.1c3.7,-0 8.1,-2 18,-8.4 8.1,-5.2 12,-6.6 18.2,-6.6 6.2,-0 10.1,1.4 18.2,6.6 10,6.4 14.3,8.4 18,8.4 3.3,-0.1 3.3,-0.1 -6.2,-9.1 -12.4,-11.7 -17.6,-14.3 -29,-14.6 -5.4,-0.2 -9.8,0.3 -12.2,1.2z"
android:fillColor="#000000"
android:strokeColor="#00000000"/>
<path
android:pathData="M57.4,57.9c-6,3.7 -6.6,12.1 -1.2,16.6 4,3.4 9.6,3.4 13.6,-0 3.8,-3.2 4.8,-6.3 1.8,-5.8 -3.2,0.7 -7.6,-3.3 -7.6,-6.7 0,-1.6 0.5,-3.2 1,-3.5 1.9,-1.2 1,-2.5 -1.7,-2.5 -1.6,-0 -4.2,0.9 -5.9,1.9z"
android:fillColor="#000000"
android:strokeColor="#00000000"/>
<path
android:pathData="M37.5,63.1c-3.3,1.6 -7.2,2.9 -8.7,2.9 -1.6,-0 -2.8,0.4 -2.8,1 0,2.5 10.6,11.2 18.7,15.2 8.4,4.2 8.9,4.3 18.3,4.3 9.4,-0 9.9,-0.1 18.3,-4.3 8.1,-4 18.7,-12.6 18.7,-15.1 0,-0.6 -1.3,-1.1 -2.9,-1.1 -1.5,-0 -5.5,-1.3 -8.7,-3 -3.2,-1.6 -6,-3 -6.1,-3 -0.1,-0 0.2,1.2 0.8,2.7 2.4,6.5 -2.2,15.3 -10.2,19.4 -5.2,2.6 -14.6,2.6 -19.8,-0.1 -7.5,-3.8 -12.1,-12.2 -10.2,-18.8 0.5,-1.8 0.9,-3.2 0.8,-3.1 -0.1,-0 -2.9,1.4 -6.2,3z"
android:fillColor="#000000"
android:strokeColor="#00000000"/>
</vector>
Your OP will
You can take a circle as a background for image view and set its src as the vector
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:src="#drawable/eye"
android:tint="#747474"
android:background="#drawable/circle_gray"
android:padding="6dp"/>
circle_gray.xml in drawable folder
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke android:width="2dp"
android:color="#747474"/>
</shape>
Change width and height as per requirement . also better take color in colors.xml
Result:-
You can use this way to make circular border,
vector for round border,
And finally use your eye image in second item in layerlist. Will work fine.
It looks like this,
Android studio 3.6
Here VectorDrawable (res/drawable/ic_phone_bw.xml)
<vector android:height="24dp" android:viewportHeight="294.8"
android:viewportWidth="294.8" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FFFFFF" android:pathData="M147.4,147.4m-141.73,0a141.73,141.73 0,1 1,283.46 0a141.73,141.73 0,1 1,-283.46 0"/>
<path android:fillColor="#FF000000" android:pathData="M147.4,147.4m-131.99,0a131.99,131.99 0,1 1,263.98 0a131.99,131.99 0,1 1,-263.98 0"/>
<path android:fillColor="#FFFFFF" android:pathData="M200.62,248.9H94.19c-1.39,0 -2.52,-1.13 -2.52,-2.52V49.48c0,-1.39 1.13,-2.52 2.52,-2.52h106.43c1.39,0 2.52,1.13 2.52,2.52v196.9C203.13,247.77 202.01,248.9 200.62,248.9z"/>
<path android:fillColor="#FF000000" android:pathData="M102.7,75.7h89.39v149.58h-89.39z"/>
</vector>
I want to use it in Preference like this:
But here result:
Why icon show not correct (black dot)?
For reference, here is a SVG equivalent of your VectorDrawable.
<svg width="240px" height="240px" viewBox="0 0 294.8 294.8">
<path fill="#FFFFFF" d="M147.4,147.4m-141.73,0a141.73,141.73 0,1 1,283.46 0a141.73,141.73 0,1 1,-283.46 0"/>
<path fill="#000000" d="M147.4,147.4m-131.99,0a131.99,131.99 0,1 1,263.98 0a131.99,131.99 0,1 1,-263.98 0"/>
<path fill="#FFFFFF" d="M200.62,248.9H94.19c-1.39,0 -2.52,-1.13 -2.52,-2.52V49.48c0,-1.39 1.13,-2.52 2.52,-2.52h106.43c1.39,0 2.52,1.13 2.52,2.52v196.9C203.13,247.77 202.01,248.9 200.62,248.9z"/>
<path fill="#000000" d="M102.7,75.7h89.39v149.58h-89.39z"/>
</svg>
Note that there are two black and two white paths in this icon.
There could be several things happening here:
There is something in the white third path that Android doesn't like (doesn't parse correctly), causing that path to not be drawn properly. This is unlikely.
I notice that the icons in your screenshots have a tint to them. They are grey rather than black. My guess is that you are tinting or setting the colour of the icon in a way that is setting all the paths to grey - including the white ones.
Assuming #2 is correct, thereare a couple of solutions:
Change the way you are recolouring the icons
Redraw this icon so that it consists of just one or two black paths. The parts that are white now, should instead just be holes in the black parts. Then you colour the icon, there will no longer be any white parts that get recoloured.
For example, I have ic_chat_black_24dp.xml vector asset from Android Studio,
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM6,9h12v2L6,11L6,9zM14,14L6,14v-2h8v2zM18,8L6,8L6,6h12v2z"/>
What I want is to have the start point M20,7 i.e. start the image 5dp down; all lines, everything. I can change the ViewportHeight to 29.0 to enhance the canvass but how do I use it?
Do I have to change each Y axis value individually or there's a faster way?
You can move the entire path by wrapping it in a <group> tag, which would look something like:
<group
android:translateY="5">
<path
...your stuff.../>
</group>
The group also allows you to change 'scale' and 'rotation' properties as listed in the documentation.
I am creating drawable in xml using the vector. I am able to draw a rectangle using the path but when I am trying to draw a completely vertical or horizontal line its not showing.
Here is my code
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:strokeWidth="1"
android:strokeColor="#c1ae1e"
android:pathData="M0 0,H24,V24,H0,V0"/>
<path
android:strokeWidth="3"
android:strokeColor="#4c4c4c"
android:fillColor="#36352c"
android:pathData="M12 0,L12 24"/>
<path
android:strokeWidth="3"
android:strokeColor="#4c4c4c"
android:fillColor="#36352c"
android:pathData="M0 12,L24 12"/>
</vector>
And here is the preview output-
Try combining it into one path. I'm not sure why, but having a completely horizontal or vertical line with only two points will not render. Since I had to make a cross shape, I was able to get away with combining both the vertical or horizontal lines like so:
<path
android:strokeColor="#FF000000"
android:strokeWidth="0.5"
android:pathData="M14,0 l0,28 M0,14 l28,0"/>
This will also happen if you make an arc that calculates to be a straight like (not something most people would do, but I've seen it while changing arc values, and might be related as to why the lines do not show)
Give this a try:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:strokeWidth="1"
android:strokeColor="#c1ae1e"
android:pathData="M0 0,H24,V24,H0,V0"/>
<path
android:strokeWidth="3"
android:strokeColor="#4c4c4c"
android:fillColor="#36352c"
android:pathData="M12 0,L12 24 M0 12,L24 12"/>
</vector>