android imageview.setBackgroundResource() doesn't work

纵饮孤独 提交于 2019-11-29 01:31:10

By convention, you should be using setImageResource(R.drawable.img1); (or setImageDrawable(getResources().getDrawable(R.drawable.img1));) instead of setBackgroundResource(R.drawable.img1);.

  ImageView i = (ImageView) findViewById( R.id.imageView1 );
  i.setImageResource(R.id.logo);

   or

  i.setBackgroundResource(R.drawable.icon);

UPDATE

Now, you can use like below,

imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.img1));
chirag khandla

Try This In API 25

imgSchedule.setImageDrawable(getResources().getDrawable(R.drawable.circle_image_selected));

Its no convention that setimageResource() should be used. Both the APIs can be used.

Also, in your case, it just looks like the case of out of sync resources.

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