I'm using material design theme for my toolbar and I'm using a custom instagram icon on one of the tabs. The problem is instead of an icon, only black or white shape of it is being displayed. How do I fix it?
Thank you.
View from different tab
View from instagram tab
Here's my icon XML:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:fillColor="#834fe2"
android:pathData="M15 0H497A15 15 0 0 1 512 15V497A15 15 0 0 1 497 512H15A15 15 0 0 1 0 497V15A15 15 0 0 1 15 0Z" />
<path
android:pathData="M186 108H326A78 78 0 0 1 404 186V326A78 78 0 0 1 326 404H186A78 78 0 0 1 108 326V186A78 78 0 0 1 186 108Z"
android:strokeWidth="29"
android:strokeColor="#fbfbfb" />
<path
android:pathData="M325 256A69 69 0 0 1 187 256A69 69 0 0 1 325 256Z"
android:strokeWidth="29"
android:strokeColor="#fbfbfb" />
<path
android:fillColor="#fbfbfb"
android:pathData="M362 169A19 19 0 0 1 324 169A19 19 0 0 1 362 169Z" />
Here's my styles value:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimaryDark</item>
<item name="colorPrimaryDark">#color/colorPrimary</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Here's my colors value:
<resources>
<color name="colorPrimary">#834fe2</color>
<color name="colorPrimaryDark">#fbfbfb</color>
<color name="colorAccent">#52b7f8</color>
<color name="backgroundFragment">#fbfbfb</color>
Modified the vector to remove the unnecessary background. The TabLayout tints the icons depending on the selection state. Your image contained a non-transparent background that was getting tinted together with the image.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="512dp"
android:height="512dp"
android:viewportWidth="512"
android:viewportHeight="512">
<path
android:pathData="M186 108H326A78 78 0 0 1 404 186V326A78 78 0 0 1 326 404H186A78 78 0 0 1 108 326V186A78 78 0 0 1 186 108Z"
android:strokeWidth="29"
android:strokeColor="#fbfbfb" />
<path
android:pathData="M325 256A69 69 0 0 1 187 256A69 69 0 0 1 325 256Z"
android:strokeWidth="29"
android:strokeColor="#fbfbfb" />
<path
android:fillColor="#fbfbfb"
android:pathData="M362 169A19 19 0 0 1 324 169A19 19 0 0 1 362 169Z" />
</vector>
Related
How can i convert this SVG file into a Animated vector drawable for android to show on the activity image.
SVG file
<svg width="38" height="38" viewBox="0 0 38 38" xmlns="http://www.w3.org/2000/svg" stroke="#E31F64">
<g fill="none" fill-rule="evenodd">
<g transform="translate(1 1)" stroke-width="2">
<circle stroke-opacity=".5" cx="18" cy="18" r="18"/>
<path d="M36 18c0-9.94-8.06-18-18-18">
<animateTransform
attributeName="transform"
type="rotate"
from="0 18 18"
to="360 18 18"
dur="1s"
repeatCount="indefinite"/>
</path>
</g>
</g>
</svg>
I used some online tools to convert it but they simply creates a vector not the animated vector
Here is the vector
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="38dp"
android:height="38dp"
android:viewportWidth="38"
android:viewportHeight="38">
<group
android:translateX="1"
android:translateY="1">
<path
android:fillType="evenOdd"
android:strokeAlpha=".5"
android:strokeWidth="2"
android:pathData="M 18 0 C 27.941125497 0 36 8.05887450305 36 18 C 36 27.941125497 27.941125497 36 18 36 C 8.05887450305 36 0 27.941125497 0 18 C 0 8.05887450305 8.05887450305 0 18 0 Z" />
<path
android:fillType="evenOdd"
android:strokeWidth="2"
android:pathData="M36 18c0-9.94-8.06-18-18-18" />
</group>
</vector>
How can i create animated out of this to show spinning oval.
Thanks
Use ShapeShifter tool to create Animated Vector Drawable. It is a very basic tool yet fulfills the need.
I want to make a button shape like this
Is there a way to do this with XML?
Actually I am looking for like this
It is not exactly what you are looking for, because it is not with realized with a XML. However with the new MaterialButton it is very simple to obtain it:
Just define the Button in your layout:
<com.google.android.material.button.MaterialButton
app:cornerRadius="0dp"
android:paddingLeft="24dp"
android:paddingRight="12dp"
.../>
Then just use the ShapeAppearanceModel to define a custom shape.
float size = getResources().getDimension(R.dimen.cutout_size); //18dp
TriangleEdgeTreatment triangleEdgeTreatment = new TriangleEdgeTreatment(size,true);
CutCornerTreatment cutCornerTreatment = new CutCornerTreatment(size);
button.setShapeAppearanceModel(button.getShapeAppearanceModel()
.toBuilder()
.setLeftEdge(triangleEdgeTreatment)
.setTopRightCorner(cutCornerTreatment)
.setBottomRightCorner(cutCornerTreatment)
.build());
Using more buttons (use button.setBackgroundTintList(..) or app:backgroundTint="..." in xml to change the backgroundColor) you can obtain something like:
I have achieved this by vector.
#KinjalShah Please look into this.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="138.25dp"
android:height="23dp"
android:viewportWidth="138.25"
android:viewportHeight="23">
<path android:pathData="M132.53,22.48l-132.27,0l5.36,-10.95l-5.36,-10.94l132.27,0l5.36,10.94z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="137.8946"
android:endY="11.535"
android:startX="0.2646"
android:startY="11.535"
android:type="linear">
<item
android:color="#3b0b7b"
android:offset="0" />
<item
android:color="#6244A5"
android:offset="1" />
</gradient>
</aapt:attr>
</path>
</vector>
You can make drawable for this, this is below code which exactly you want, for the process how i have created this, you can check here in the link https://stackoverflow.com/a/57443999/7216511
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
android:viewportWidth="1870"
android:viewportHeight="490"
android:width="187dp"
android:height="49dp">
<path
android:pathData="M0 245l0 -245 935 0 935 0 0 245 0 245 -935 0 -935 0 0 -245z"
android:fillColor="#F99E3F" />
<path
android:pathData="M1 245l0 -245 934 0 935 0 0 245 0 245 -935 0 -934 0 0 -245z"
android:fillColor="#E4CFBA" />
<path
android:pathData="M4 378c6 -136 6 -117 0 -260l-5 -118 935 0 936 0 0 245 0 245 -936 0 -935 0 5 -112z"
android:fillColor="#D5D5D5" />
<path
android:pathData="M4 378c6 -136 6 -117 0 -260l-5 -118 935 0 936 0 0 50c0 28 -5 50 -10 50 -7 0 -7 6 0 19 6 12 10 92 9 195l-1 176 -934 0 -935 0 5 -112zm1811 -57l34 -69 -35 -76 -35 -76 -879 0c-484 0 -880 2 -880 5 0 3 15 36 34 73l34 68 -33 72 -34 72 879 0 880 0 35 -69z"
android:fillColor="#E5DBCF" />
<path
android:pathData="M4 378c7 -138 7 -128 0 -265l-6 -113 936 0 936 0 0 50c0 28 -5 50 -10 50 -7 0 -7 6 0 19 13 25 13 227 0 252 -7 13 -7 19 0 19 5 0 10 22 10 50l0 50 -936 0 -936 0 6 -112zm1811 -58l35 -70 -34 -75 -35 -75 -880 0c-485 0 -881 3 -881 8 1 4 16 36 34 72l34 65 -34 67c-19 37 -34 70 -34 73 0 3 396 5 880 5l880 0 35 -70z"
android:fillColor="#EEEEEE" />
</vector>
I want to use svg drawable with Android Studio. I use drawable->New->Vector Asset->Local File, but it doesn't import my svg file. I try this file with svg2android it throws some warnings.
Warning #1: stroke-width not found on path one or more times. Defaulting all instances to 1.
Warning #2: transforms on path are not supported, use option Bake transforms into path
Generated xml file is below:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<path
android:strokeColor="#66899a"
android:strokeWidth="1"
android:pathData="M 0 -44 C 3.31370849898 -44 6 -24.3005289926 6 0 C 6 24.3005289926 3.31370849898 44 0 44 C -3.31370849898 44 -6 24.3005289926 -6 0 C -6 -24.3005289926 -3.31370849898 -44 0 -44 Z" />
<path
android:strokeColor="#e1d85d"
android:strokeWidth="1"
android:pathData="M 0 -44 C 3.31370849898 -44 6 -24.3005289926 6 0 C 6 24.3005289926 3.31370849898 44 0 44 C -3.31370849898 44 -6 24.3005289926 -6 0 C -6 -24.3005289926 -3.31370849898 -44 0 -44 Z" />
<path
android:strokeColor="#80a3cf"
android:strokeWidth="1"
android:pathData="M 0 -44 C 3.31370849898 -44 6 -24.3005289926 6 0 C 6 24.3005289926 3.31370849898 44 0 44 C -3.31370849898 44 -6 24.3005289926 -6 0 C -6 -24.3005289926 -3.31370849898 -44 0 -44 Z" />
<path
android:strokeColor="#4b541f"
android:strokeWidth="1"
android:pathData="M 0 -44 C 24.3005289926 -44 44 -24.3005289926 44 0 C 44 24.3005289926 24.3005289926 44 0 44 C -24.3005289926 44 -44 24.3005289926 -44 0 C -44 -24.3005289926 -24.3005289926 -44 0 -44 Z" />
Does android support fully svg? If yes, how can I import this file? Also, I want to set background drawable programmatically. Is it possible without using R.drawable.svgXml? Can I generate bitmap from xml?
Does android support fully svg?
Obviously not, otherwise it would not show you those warnings that state "X not supported".
You have to change the SVG if you want to use it.
Can I generate bitmap from xml?
See here How to get a Bitmap from a drawable defined in a xml?
I was trying to add a vector drawable to Android studio
Using the vector asset in Android studio, I've imported a psd file, it but it seems like there is a rendering problem as the preview and the result xml file are empty, please check the
output xml screenshot.
In your screenshot there is no pathdata in the file. Hence, nothing is drawn on screen. I am showing contents of a VectorDrawable xml file. Copy the contents into a blank xml file in android studio and see the shape drawn in blue on screen.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="600dp"
android:height="600dp"
android:viewportWidth="800.0"
android:viewportHeight="800.0">
<path
android:pathData="M 162 8
q -07 00 -41 26
q -34 27 -50 64
q -25 59 -19 117
q 07 70 53 121
q 57 63 151 62
q 87 -01 140 -66
q 46 -55 48 -142
q 01 -56 -34 -105
q -38 -52 -77 -70
l -29 -11
q 16 -01 31 -02
q 59 -01 119 -02
"
android:strokeLineCap="round"
android:strokeColor="#f00f"
android:fillColor="#00000000"
android:strokeWidth="32"/>
</vector>
I have a vector image (svg converted to xml):
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:better="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
tools:ignore="NewApi"
android:viewportWidth="24"
better:viewportWidth="24"
android:viewportHeight="24"
better:viewportHeight="24"
android:width="24dp"
android:height="24dp">
<path
android:pathData="M10.09 15.59l1.41 1.41 5 -5 -5 -5 -1.41 1.41 2.58 2.59 -9.67 0 0 2 9.67 0 -2.58 2.59zM19 3L5 3C3.89 3 3 3.9 3 5l0 4 2 0 0 -4 14 0 0 14 -14 0 0 -4 -2 0 0 4c0 1.1 0.89 2 2 2l14 0c1.1 0 2 -0.9 2 -2L21 5C21 3.9 20.1 3 19 3Z"
better:pathData="M10.09 15.59l1.41 1.41 5 -5 -5 -5 -1.41 1.41 2.58 2.59 -9.67 0 0 2 9.67 0 -2.58 2.59zM19 3L5 3C3.89 3 3 3.9 3 5l0 4 2 0 0 -4 14 0 0 14 -14 0 0 -4 -2 0 0 4c0 1.1 0.89 2 2 2l14 0c1.1 0 2 -0.9 2 -2L21 5C21 3.9 20.1 3 19 3Z"
android:fillColor="#color/menu_color_selector"
better:fillColor="#color/menu_color_selector" />
</vector>
But the color selector doesn't work. Is it possible to achieve what I am trying to do?
Try to use StateListDrawable with different VectorDrawable for each required state.