Android Set Vector Drawables to ImageView

June 18, 2019

Edit Module build.gradle.

android {
    ...
    defaultConfig {
        ...
        vectorDrawables.useSupportLibrary = true
    }

    ...

}

In layout file, use app:srcCompat.

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/ic_keyboard_arrow_right_black_24dp" />

Set Vector Drawable to ImageView programatically.

imageView.setImageResource(context, R.drawable.ic_keyboard_arrow_right_black_24dp)

NOTE: Refer Get Drawable Of Vector Resource (with support library backward compatibility).

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.