How to set VectorDrawable as an image for ImageView programmatically

后端 未结 8 1586
梦如初夏
梦如初夏 2020-12-13 05:58

I want to set some vectorDrawables to a ImageView in Android Studio.

I can set png and jpg drawable easily but when i want to set V

8条回答
  •  轮回少年
    2020-12-13 06:13

    if you are concerned with the backward compatibility then you should use AppCompatImageView instead of image view. go through the code below.

    
    

    java

    AppCompatImageView image = (AppCompatImageView) findViewById(R.id.iv_about);
    image.setImageResource(R.drawable.ic_vector_image);
    

    below code need to add in build.gradle

    android { defaultConfig{ vectorDrawables.useSupportLibrary = true } }

    And it will serve the perspective of app:srcCompat.

提交回复
热议问题