I want to move the arrow a little to the right.
You can edit your icon to move it a little to the right.
If you use Raster image, just use image editor, which you like and move it.
If you use Vector image, you can wrap your path data with group and add scale and pivot to the image:
Initial vector file:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M8,5v14l11,-7z" />
</vector>
Image moved to the right:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<group
android:pivotX="-30"
android:scaleX="0.95"
android:scaleY="0.95">
<path
android:fillColor="#FF000000"
android:pathData="M8,5v14l11,-7z" />
</group>
</vector>
FAB now looks in a next way:
You can move your image to any side using pivotX and pivotY.
No corresponding attribute.
Only possible via editing drawables.
Way to alter vectors on Android ref.
Related
I crated a Vector asset using Android studio and I have the following code:
<vector android:height="24dp" android:tint="#4CAC78"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#android:color/white" android:pathData="M23,12l-2.44,-2.78 0.34,-3.68 -3.61,-0.82 -1.89,-3.18L12,3 8.6,1.54 6.71,4.72l-3.61,0.81 0.34,3.68L1,12l2.44,2.78 -0.34,3.69 3.61,0.82 1.89,3.18L12,21l3.4,1.46 1.89,-3.18 3.61,-0.82 -0.34,-3.68L23,12zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
</vector>
The result looks like this:
The problem is that the exclamation mark is transparent and I would like to make it non-transparent. I tried to change the attribute path android:fillColor="#android:color/blackbut this did not have any effect. Any idea how I can do this?
The green area and the exclamation mark are really created by two separate paths that are combined into the single path statement in the vector drawable. To color them separately, you need to separate them out into separate path statements:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#4CAC78"
android:pathData="M23,12l-2.44,-2.78 0.34,-3.68 -3.61,-0.82 -1.89,-3.18L12,3 8.6,1.54 6.71,4.72l-3.61,0.81 0.34,3.68L1,12l2.44,2.78 -0.34,3.69 3.61,0.82 1.89,3.18L12,21l3.4,1.46 1.89,-3.18 3.61,-0.82 -0.34,-3.68L23,12z" />
<path
android:fillColor="#android:color/black"
android:pathData="M13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z" />
</vector>
I was looking for an torch on and torch off icon in Android Studio's vector asset search for a camera app. I couldn't find either, but I found a similar icon (vector xml) called as highlight.
I have used it as a placeholder for torch on. I wanted to remove the three rectangles and increase the height of the torch holder to cover the remaining height for torch off icon. Is it possible to achieve this? If yes...then how could one achieve it...if not, then what alternative could I go with?
Code:
<?xml version="1.0" encoding="utf-8"?>
<vector
android:height="24dp"
android:tint="#FFFFFF"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="#android:color/white"
android:pathData="M6,14l3,3v5h6v-5l3,-3V9H6V14zM11,2h2v3h-2V2zM3.5,5.88l1.41,-1.41l2.12,2.12L5.62,8L3.5,5.88zM16.96,6.59l2.12,-2.12l1.41,1.41L18.38,8L16.96,6.59z"/>
</vector>
here is the vector you asked for
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#android:color/white"
android:pathData="M6,14l3,3v7h6v-7l3,-3V9H6V14zM11,1" />
I am trying to create pencil icon using lines (xml definition). But not getting exact shape. Whether it is possible or not?
You can use the pencil icon from Android Studio itself from File->New->Vector Asset and then click on clip art icon and search for your specific image. You can also change its color through its XML.
Or you can download the SVG image from https://www.flaticon.com/ and choose the image which you want. You can also change its color from XML after using in the Android Studio.
A sample XML for vector drawable pencil icon.
<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="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
If you want to use Vector Drawable try using below code for drawable.xml
<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="#color/colorPrimary"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>
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've taken out this icon SVG and I've edited it in Inkscape to make the double tick icon look like the WhatsApp one.
So, later in Android Studio I put the original vector drawable icon:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M0.41,13.41L6,19L7.41,17.58L1.83,12M22.24,5.58L11.66,16.17L7.5,12L6.07,13.41L11.66,19L23.66,7M18,7L16.59,5.58L10.24,11.93L11.66,13.34L18,7Z" />
</vector>
And then I've replaced the pathData with the SVG path edited in Inkscape:
<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="#000"
android:pathData="M 0.41,13.41 6,19 7.41,17.58 1.83,12 M 22.24,5.58 11.66,16.2 11,15.5 9.5,17 11.66,19 23.66,7 M 18,7 16.5,5.5 4.5, 17.5 6,19 Z"/>
</vector>
I can see the new icon in Android Studio preview, but when I run the app it doesn't show. Normal icons does show normally, but this one doesn't.
It's a weird behavior that I cannot understand, I'm pretty new into vector graphics.
Why is that?
I've found the answer by myself. Looking at the original icon syntax it appears that spaces should be given with an L letter.
<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="#8A000000" android:pathData="M0.41,13.41L6,19L7.41,17.58L1.83,12M22.24,5.58L11.66,16.2L11,15.5L9.5,17L11.66,19L23.66,7M18,7L16.5,5.5L4.5,17.5L6,19Z"/>
</vector>
Now it works. Funny how I didn't know anything about vector drawable, and still found a solution.