How can I make this shape using xml drawable? Been fighting over it quite some time and can't get it done.
Android - Make check icon using xml drawable
Asked Answered
Have you considered using a 9patch image of this? Or why do you need this as a shape? –
Eighteen
You could also convert the image to a vector drawable –
Fencesitter
you can't create check mark simply with drawable.xml , use image for that or write your own logic for that. –
Moulmein
I will need to show it full screen so I figured i wouldn't use a large image that would increase my apk size –
Calton
Here is the template you could improve:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="30dp"
android:height="4dp"
android:top="20dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_orange_dark"/>
</shape>
</rotate>
</item>
<item
android:width="40dp"
android:height="4dp"
android:top="15dp"
android:left="18dp">
<rotate
android:fromDegrees="-45">
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_orange_dark"/>
</shape>
</rotate>
</item>
<item
android:width="50dp"
android:height="50dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
</shape>
</item>
</layer-list>
This is a great answer but I'm getting this warning Attribute height is only used in API level 23 and higher (current min is 16). What attributes should I use for API less than 23. –
Spent
2020 Solution:
For anyone looking for this answer now, you can download the icon on the material website (https://material.io/resources/icons/?style=baseline)
For android, you can even directly add the icon from Android Studio using:
- 1 -> "Resource Manager" on the left
- 2 -> pressing the "+" icon
- 3 -> selecting "Vector Asset"
- 4 -> then you just have to select the proper icon
or you could:
- 1 -> right click on the res/drawable folder
- 2 -> select New > Vector Asset
This is the best solution! Use what AS provides for you. –
Augend
Yes, but you can create clone of a png one.... –
Falzetta
Not sure what you mean @NSV.? When you use my solution, the icon name start with "ic_", so you also use png drawable starting with "ic_" ? You may use a naming convention to make sure you don't have png icons with the same name –
Geese
Typo, i meant you can just not use the vector asset,directly link to png, commented since i know its not a good solution –
Falzetta
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#008F28"
android:alpha="0.9">
<path
android:fillColor="#FF000000"
android:pathData="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="25dp"
android:height="4dp"
android:top="20dp">
<rotate
android:fromDegrees="45">
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_orange_dark"/>
</shape>
</rotate>
</item>
<item
android:width="40dp"
android:height="4dp"
android:top="15dp"
android:left="13dp">
<rotate
android:fromDegrees="-45">
<shape
android:shape="rectangle">
<solid android:color="@android:color/holo_orange_dark">
</solid>
</shape>
</rotate>
</item>
<item
android:width="50dp"
android:height="50dp">
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
</shape>
</item>
© 2022 - 2024 — McMap. All rights reserved.