简体   繁体   中英

Android drawable shape in xml

How I can create single vector xml drawable like this (black shape):

在此处输入图片说明

To be able to use this in imageView and change it color

To create the required shape as a vector drawable, use the following code.

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="48dp"
    android:height="48dp"
    android:viewportHeight="12"
    android:viewportWidth="12">

<path
    android:fillColor="Set_Your_Color"
    android:pathData="M 2,9 C 2,9 4,10 6,10 C 8,10 10,9 10,9 L 10,0 2,0 2,8"
    android:strokeWidth="0.1"/>

 </vector>

Edit the values in the vector to fit it exactly to your requirements.

To use the vector drawable in ImageView, you can either do it programmatically using:

image.setImageResource(R.drawable.myDrawable);

or by XML:

app:srcCompat="@drawable/mydrawable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM