How to Set BackgroundColor on ImageView on Android?

拈花ヽ惹草 提交于 2019-12-03 04:22:28

RGB:255, 255, 255 is the color code for WHITE. Since your parent layout background color is also white you won't see the difference.

Try changing color like

backgroundImg.setBackgroundColor(Color.rgb(100, 100, 50));

Or else change the background color of parent layout.

There's nothing wrong with your code. But I would prefer doing this through xml , This will also solve your problem. Just add this in your ImageView tag.

android:background="@android:color/black"

In theory it should work...but try like this:

backgroundImg.setBackgroundColor(Color.parseColor("#FFFFFF"));
makuno

If you want to use a XML file placed in drawable folder, you might need to use:

imageView.setBackgroundResource(R.drawable.drawable);
Sunil Chaudhary

Using PorterDuff.Mode:

imageView1.setColorFilter(colorCode,android.graphics.PorterDuff.Mode.SRC_IN);

PorterDuff.mode gives a way of composing and overlaying images in Android, see also What does PorterDuff.Mode mean in android graphics.What does it do?

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