Suraj Singh
Suraj Singh

Reputation: 11

How to get drawable resource in android programmatically?

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.

Upvotes: 1

Views: 887

Answers (1)

jayesh gurudayalani
jayesh gurudayalani

Reputation: 1701

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

ContextCompat.getDrawable(Context context,int drawableId)

Upvotes: 4

Related Questions