How to get drawable resource in android programmatically?

357 views Asked by At

I want to get the drawable id which is shown in the screen. I used if(getResources().getDrwable(binding.image1)==R.drawable.image){ //my stuff} But this is depreciated.

1

There are 1 answers

0
jayesh gurudayalani On

You can use alternative of getResources().getDrawable(int id) as mentioned below

ContextCompat.getDrawable(Context context,int drawableId)