-1

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.

Mohanish
  • 459
  • 2
  • 13

3 Answers3

2

Try setImageResource() method:

.setImageResource(R.drawable.your_image);
IntelliJ Amiya
  • 73,189
  • 14
  • 161
  • 193
1

Below is the code

For Src:

img.setImageResource(R.drawable.icon);

For Background:

img.setBackgroundResource(R.drawable.icon);
PankajAndroid
  • 2,645
  • 3
  • 26
  • 41
0

Try this

imageView.setImageDrawable(ResourcesCompat.getDrawable(getResources(),R.drawable.imageID, null));

https://stackoverflow.com/questions/29041027

Community
  • 1
  • 1