How to get Image Resource

牧云@^-^@ 提交于 2019-12-10 02:44:54

问题


How should I get current image resource of an imageButton? I need something like this:

imageButton.getImageResource(); 

Thanks a lot


回答1:


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();



回答2:


You can use imageButton.getDrawable() to get the drawable of the ImageButton object and then use setImageDrawable() instead of setImageResource().




回答3:


Use this

imageButton.setImageResource(R.drawable.your_resource);
imageButton.setTag(R.drawable.your_resource);

Integer resource = (Integer) imageButton.getTag();

if(resource == R.drawable.your_resource){
    // do something
}else {
}


来源:https://stackoverflow.com/questions/26370993/how-to-get-image-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!