Vector Drawable in the circle

qbait picture qbait · Mar 20, 2018 · Viewed 13k times · Source

is there an easy way to generate Vector Drawable that is a circle with the icon inside from the existing vector drawable?

Example: existing vector drawable

generated vector drawable, circle with empty icon inside

Answer

DimDim picture DimDim · Mar 20, 2018

I would suggest something like this:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
    android:gravity="fill"
    android:drawable="@drawable/ic_brightness_1_black_24dp"

    />
    <item
        android:gravity="center"
        android:drawable="@drawable/ic_call_black_24dp"
        android:top="20dp"
        android:bottom="20dp"
        android:left="20dp"
        android:right="20dp"
        />

</layer-list>

The resources with ids ic_brightness_1_black_24dp and ic_call_black_24dp are imported vector drawables.

ic_brightness_1_black_24dp:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#303F9F"
        android:pathData="M12,12m-10,0a10,10 0,1 1,20 0a10,10 0,1 1,-20 0"/>
</vector>

and ic_call_black_24dp:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFF"
        android:pathData="M6.62,10.79c1.44,2.83 3.76,5.14 6.59,6.59l2.2,-2.2c0.27,-0.27 0.67,-0.36 1.02,-0.24 1.12,0.37 2.33,0.57 3.57,0.57 0.55,0 1,0.45 1,1V20c0,0.55 -0.45,1 -1,1 -9.39,0 -17,-7.61 -17,-17 0,-0.55 0.45,-1 1,-1h3.5c0.55,0 1,0.45 1,1 0,1.25 0.2,2.45 0.57,3.57 0.11,0.35 0.03,0.74 -0.25,1.02l-2.2,2.2z"/>
</vector>