Search code examples
javaandroidandroid-studiosvgandroid-vectordrawable

How to create vector drawables for android?


I am new to VectorDrawables.

I can see that the default vector drawables provided with android studio like ic_menu_gallery, ic_menu_camera, etc. are working great. So I tried to create my own vector drawables by converting my png images to svg first and using the path and fill values to make vector drawables i.e replaced the android:pathData for d and android:fillColor for fill tag in svg files. It somehow gave vector drawables but distorted or currputed looking.

If I am not taking the right approach please suggest me.


Solution

  • You can use Android Studio. Convert png to svg file online tools PNG to SVG
    File - > New -> Vector Asset

    You can choose Material Icon or Local SVG file

    For SVG color can use :

      <ImageButton
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:id="@+id/button"
        android:src="@drawable/ic_more_vert_24dp"
        android:tint="@color/primary" />
    

    Or

    imageView.setColorFilter(getResources().getColor(android.R.color.black), PorterDuff.Mode.SRC_IN);
    

    Can convert SVG to PNG online tool: coolutils

    Convert SVG to Android drawable: inloop