Reputation: 469
How to change the imageview's src as well as background programatically not in xml?
setBackgroundResource() : same behaviour as setBackground().
But in xml, we got the option to set the src as well as background.
Any help appreciated. Thanks.
Upvotes: 0
Views: 1602
Reputation: 75788
Try setImageResource()
method:
.setImageResource(R.drawable.your_image);
Upvotes: 2
Reputation: 2707
Below is the code
For Src:
img.setImageResource(R.drawable.icon);
For Background:
img.setBackgroundResource(R.drawable.icon);
Upvotes: 2
Reputation: 47
Try this
imageView.setImageDrawable(ResourcesCompat.getDrawable(getResources(),R.drawable.imageID, null));
https://stackoverflow.com/questions/29041027
Upvotes: 0