Android - Make check icon using xml drawable
Asked Answered
C

4

10

enter image description here

How can I make this shape using xml drawable? Been fighting over it quite some time and can't get it done.

Calton answered 8/9, 2016 at 9:34 Comment(4)
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 drawableFencesitter
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 sizeCalton
P
15

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>
Pietrek answered 8/9, 2016 at 9:46 Comment(1)
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
G
6

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
Geese answered 31/12, 2020 at 15:38 Comment(4)
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 nameGeese
Typo, i meant you can just not use the vector asset,directly link to png, commented since i know its not a good solutionFalzetta
L
2
<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>
Lindbom answered 28/7, 2021 at 7:45 Comment(0)
G
1
<?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>
Guzman answered 13/7, 2020 at 12:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.