How should I get current image resource of an imageButton? I need something like this:
imageButton.getImageResource();
Thanks a lot
A string representing the accessible name of the image. In an API, an image resource is represented as an ImageResource dictionary. In [ JSON ], image resource is represented as an object.
You can use imageButton. getDrawable() to get the drawable of the ImageButton object and then use setImageDrawable() instead of setImageResource() .
To import image resources into your project, do the following: Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.
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.
I think you can't, current API doesn't allow this. But if you really need this, you can do something like this:
imageButton.setImageResource(R.drawable.your_resource);
imageButton.setTag(R.drawable.your_resource);
//
// somewhere later...
//
Integer resource = (Integer)imageButton.getTag();
You can use imageButton.getDrawable() to get the drawable of the ImageButton object and then use setImageDrawable() instead of setImageResource().
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