I have set an image to an ImageView
control in android:
iv.setImageResource(R.drawable.image1);
I want to get this associated Drawable, looks like:
Drawable myDrawable = iv.getImageResource(); //wrong
This is an easy approach if you can use the view's id member variable: just store the R. drawable id using v. setId(). Then get it back with v.
drawable id in the view's id: use v. setId() . Then get it back with v. getId() .
Step 1: In this method first of all in your system find your required images and copy the image as we do normally. Step 2: Then open the Android Studio go to the app > res > drawable > right-click > Paste as shown in the below figure. Step 3: Then a pop-up screen will arise like below.
You can get the drawable like
Drawable myDrawable = iv.getDrawable();
You can compare it with a drawable resource like
if(iv.getDrawable()==getResources().getDrawable(R.drawable.image1)){
//do work here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With