Make an arrow shape both side with xml - android

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>

Related

Material design custom icon color

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>

Android - SVG file import

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?

Android drawable, how to make this logo using vector

I need to create an Android drawable where the word oryx is writting using the below vectors:
<glyph glyph-name="O" unicode="O" horiz-adv-x="657" d="M194 268q3 -35 8.5 -55.5t20 -40.5t43.5 -29t74 -9q35 0 60 11t37 25t19 34t8 30t1 22v10.5v16t-1 19.5t-3.5 22.5t-7 22.5t-11 22.5t-17 19.5t-23.5 16.5t-31.5 10.5t-40.5 4q-40 0 -68 -11t-41 -25.5t-20 -38t-7.5 -36.5t0.5 -33v-8zM45 277q-1 6 -1.5 16t3 39 t11.5 55.5t28 58.5t49.5 55t79.5 38.5t114 15.5q45 0 83 -7t65.5 -19t49 -30t35.5 -35.5t23.5 -41.5t14.5 -41.5t7 -41t2.5 -35.5t0 -30.5t-0.5 -20.5q0 -16 -1 -29t-6 -41t-14 -50t-28.5 -48t-46 -43.5t-69 -29.5t-95.5 -12q-55 0 -98 7t-73 18.5t-52.5 31.5t-36.5 41 t-23 52t-13.5 59.5t-7.5 67.5z"/>
<glyph glyph-name="R" unicode="R" horiz-adv-x="459" d="M412 555q-1 -2 0.5 -21t-0.5 -36.5t-8 -37.5t-24.5 -32t-47.5 -12q-42 0 -65 -3t-41 -15t-24 -34t-6 -60v-320q-18 13 -47.5 20.5t-50 11.5t-36.5 23.5t-16 56.5v268q0 6 0.5 16.5t3.5 29t10 37t21 38.5t34 35t51.5 25t70.5 10h99h35h11.5h29.5z"/>
<glyph glyph-name="Y" unicode="Y" horiz-adv-x="684" d="M275 27h134l-86 -189q-38 -41 -92 -41q-24 0 -41.5 12.5t-23.5 24.5l-6 13l110 219q-2 5 -4 11q-36 88 -97 207.5t-87.5 167.5t-42.5 76l16 5t32 9t39.5 3.5t44 -6.5t41.5 -24.5t34 -49.5q14 -40 39.5 -97t44.5 -95t19 -39q67 169 93 244q13 30 33.5 48.5t40.5 24t42.5 5 t38.5 -5t30.5 -9.5t15.5 -5q-87 -175 -168 -372q-16 -37 -38.5 -64t-42 -40.5t-45 -21.5t-40 -9.5t-34.5 -1.5z"/>
<glyph glyph-name="X" unicode="X" horiz-adv-x="648" d="M48 526q15 9 37 15.5t52 8t63 -13.5t59 -47q27 -33 72 -92q54 73 86 118q31 29 71 32.5t69 -10t40 -33.5q-40 -53 -173 -231q149 -199 182 -243q-11 -19 -40 -33t-69 -10.5t-71 32.5q-34 48 -95 130q-51 -67 -81 -104q-26 -32 -59 -47t-63 -13t-52 8t-37 15 q71 98 198 265q-119 157 -189 253z"/>
I created the file drawable/oryx.xml and started with the below code trying to get the letter O but nothing appeared when i used it in the layout file as: android:background="#drawable/oryx"
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="684dp"
android:width="684dp"
android:viewportWidth="684.0"
android:viewportHeight="684.0">
<group
android:name="rotationGroup"
android:pivotX="10.0"
android:pivotY="10.0"
android:rotation="0.0" >
<path
android:name="O"
android:fillColor="#FF000000"
android:pathData="M194 268q3 -35 8.5 -55.5t20 -40.5t43.5 -29t74 -9q35 0 60 11t37 25t19 34t8 30t1 22v10.5v16t-1 19.5t-3.5 22.5t-7 22.5t-11 22.5t-17 19.5t-23.5 16.5t-31.5 10.5t-40.5 4q-40 0 -68 -11t-41 -25.5t-20 -38t-7.5 -36.5t0.5 -33v-8zM45 277q-1 6 -1.5 16t3 39 t11.5 55.5t28 58.5t49.5 55t79.5 38.5t114 15.5q45 0 83 -7t65.5 -19t49 -30t35.5 -35.5t23.5 -41.5t14.5 -41.5t7 -41t2.5 -35.5t0 -30.5t-0.5 -20.5q0 -16 -1 -29t-6 -41t-14 -50t-28.5 -48t-46 -43.5t-69 -29.5t-95.5 -12q-55 0 -98 7t-73 18.5t-52.5 31.5t-36.5 41 t-23 52t-13.5 59.5t-7.5 67.5z"
android:fillAlpha=".3"/>
</group>
</vector>
Can any one help here. the output is required to be as below. thanks
Try this ,
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="3730dp"
android:height="1220dp"
android:viewportWidth="3730"
android:viewportHeight="1220">
<path
android:fillColor="#ed7d31"
android:strokeWidth="1"
android:pathData="M1716 1167 c-14 -15 -26 -34 -26 -44 0 -10 61 -90 135 -178 111 -132 135 -166 135
-192 0 -75 -71 -523 -100 -622 -13 -45 -3 -55 66 -70 108 -25 193 10 213 87 5 20
15 93 21 162 6 69 15 141 19 160 l7 34 93 -129 c52 -72 109 -150 127 -175 48 -66
114 -127 156 -145 59 -24 177 -16 212 16 4 4 -29 52 -74 106 -46 54 -159 196 -251
315 -168 216 -239 287 -321 323 l-33 14 33 1 c19 0 32 5 32 13 0 22 -219 286 -261
314 -29 19 -58 28 -99 31 -53 4 -61 2 -84 -21z" />
<path
android:fillColor="#000000"
android:strokeWidth="1"
android:pathData="M1052 881 c-87 -31 -117 -60 -108 -106 4 -16 43 -136 87 -265 90 -261 120 -317 208
-387 87 -68 150 -83 342 -83 121 0 161 3 165 13 7 18 -22 95 -51 137 -38 54 -73 70
-177 79 -102 8 -148 27 -175 68 -10 15 -59 149 -109 297 -50 148 -95 271 -100 272
-5 0 -42 -11 -82 -25z" />
<path
android:fillColor="#000000"
android:strokeWidth="1"
android:pathData="M2660 896 c-19 -7 -36 -19 -37 -27 -1 -8 92 -99 207 -204 115 -104 210 -193 210
-197 0 -3 -32 -84 -70 -180 -39 -95 -69 -182 -68 -193 4 -25 62 -43 141 -44 96 -1
140 34 192 156 l27 62 110 -99 c119 -108 154 -126 240 -118 26 3 58 12 72 22 47 30
35 55 -76 156 -57 52 -139 127 -182 168 l-79 74 73 180 74 181 -32 28 c-58 52 -165
65 -222 27 -27 -18 -42 -43 -73 -120 l-39 -97 -101 90 c-124 110 -197 149 -276 148
-31 0 -72 -6 -91 -13z" />
<path
android:fillColor="#000000"
android:strokeWidth="1"
android:pathData="M223 875 c-72 -16 -97 -28 -136 -64 -45 -41 -57 -73 -57 -151 0 -231 132 -460 319
-553 179 -90 445 -89 544 1 78 70 90 183 37 342 -47 139 -85 206 -165 286 -78 79
-147 117 -253 140 -83 17 -207 17 -289 -1z m311 -226 c37 -13 67 -34 89 -60 62 -72
102 -217 75 -269 -45 -86 -236 -77 -324 15 -65 67 -111 229 -82 285 27 51 147 65
242 29z" />
<path
android:fillColor="#ffffff"
android:strokeWidth="1"
android:pathData="M0 610 l0 -610 1865 0 1865 0 0 610 0 610 -1865 0 -1865 0 0 -610z m1878 539 c33
-17 69 -53 153 -158 l109 -136 -50 -3 c-66 -4 -65 -24 3 -45 97 -31 162 -91 324
-300 81 -106 192 -245 245 -309 l97 -116 -31 -11 c-45 -16 -123 -14 -166 5 -56 23
-92 63 -223 244 -160 221 -156 217 -168 205 -5 -5 -17 -82 -26 -170 -9 -88 -19
-175 -21 -194 -11 -73 -89 -105 -198 -80 -42 9 -55 16 -51 26 20 54 91 475 100 594
l6 84 -135 160 c-75 88 -136 168 -136 177 0 50 90 65 168 27z m-672 -491 c88 -267
112 -324 145 -355 37 -33 92 -53 151 -53 119 -1 173 -34 208 -127 11 -30 20 -56 20
-58 0 -3 -69 -5 -154 -5 -179 0 -244 15 -325 74 -80 59 -111 118 -200 376 -94 275
-96 283 -83 307 6 10 43 30 84 44 40 15 74 27 75 28 1 0 36 -104 79 -231z m1660
202 c32 -16 103 -68 157 -115 54 -48 104 -85 111 -82 8 3 31 49 52 102 29 75 44
100 65 111 51 26 153 13 200 -25 l23 -18 -75 -182 -74 -183 52 -46 c164 -148 323
-296 323 -301 -1 -27 -52 -51 -108 -51 -74 0 -108 18 -216 115 -57 52 -109 95 -115
95 -6 0 -29 -39 -52 -86 -50 -104 -76 -124 -164 -123 -33 0 -77 6 -97 12 l-37 12
75 184 c41 101 74 186 74 190 0 3 -95 94 -212 201 l-211 194 29 13 c54 23 135 16
200 -17z m-2354 -4 c101 -22 175 -62 243 -130 70 -70 110 -142 155 -276 63 -188 37
-305 -78 -358 -45 -20 -77 -26 -158 -30 -255 -11 -450 95 -551 300 -49 98 -73 199
-73 301 0 84 20 127 77 159 75 44 259 60 385 34z" />
<path
android:fillColor="#ffffff"
android:strokeWidth="1"
android:pathData="M344 679 c-53 -15 -79 -53 -78 -112 1 -140 92 -278 203 -311 102 -30 180 -17 231
39 20 21 25 37 25 79 -2 123 -88 257 -191 295 -57 22 -136 26 -190 10z" />
</vector>

How to make border of LinearLayout in android as per following design

I have uses shape drawable to get rounded coreners but adding a semicircle in between seems tricky.
you can use vector asset studio to draw a custom shape and use it as background for your layout
https://developer.android.com/studio/write/vector-asset-studio.html
You can use Vector Drawable to achieve your end result. I used potrace to convert your image into svg format which is included at the bottom.
Use the Android Studio to create a vector drawable from this svg file.
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="271.000000pt" height="263.000000pt" viewBox="0 0 271.000000 263.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.13, written by Peter Selinger 2001-2015
</metadata>
<g transform="translate(0.000000,263.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M225 2546 c-40 -17 -84 -63 -101 -103 -12 -27 -14 -228 -14 -1140 0
-1093 0 -1107 20 -1149 12 -24 39 -54 62 -70 l41 -29 456 -3 c251 -2 471 0
489 3 23 4 32 11 32 25 0 11 7 20 15 20 8 0 19 16 25 39 14 54 79 124 142 152
74 33 191 33 265 0 61 -27 125 -92 142 -144 7 -21 17 -37 22 -37 5 0 9 -18 9
-40 0 -40 7 -49 25 -31 6 6 151 11 345 13 l335 3 36 24 c20 14 47 41 60 60
l24 35 3 1105 c1 608 0 1121 -3 1139 -8 42 -59 100 -110 123 -36 17 -73 19
-392 19 l-353 0 0 -35 c0 -24 -5 -35 -15 -35 -8 0 -24 -20 -36 -45 -25 -53
-74 -99 -138 -128 -36 -16 -66 -21 -136 -21 -79 -1 -97 3 -147 27 -90 44 -148
127 -148 211 l0 26 -462 0 c-361 -1 -470 -4 -493 -14z m920 -93 c13 -44 28
-67 70 -109 182 -177 521 -113 592 112 l17 54 335 0 c375 0 383 -1 428 -69
l23 -34 -2 -1113 -3 -1112 -25 -27 c-51 -55 -54 -55 -399 -55 l-319 0 -7 32
c-19 86 -84 160 -180 205 -52 24 -73 28 -150 28 -82 0 -97 -3 -157 -33 -84
-41 -143 -105 -164 -179 l-15 -53 -460 0 c-497 0 -487 -1 -539 55 l-25 27 -3
1111 c-2 1096 -2 1112 18 1145 11 18 34 41 52 52 32 19 52 20 465 20 l432 0
16 -57z"/>
</g>
</svg>

Color selector for vector image doesn't work

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.

Categories

Resources