How to use ColorDrawable with ImageView?

Posted by user246114 on Stack Overflow See other posts from Stack Overflow or by user246114
Published on 2010-03-30T20:29:42Z Indexed on 2010/03/30 20:33 UTC
Read the original article Hit count: 349

Filed under:
|

Hi,

I have a layout with an ImageView defined like:

<ImageView
  android:layout_width="45dip"
  android:layout_height="45dip"
  android:scaleType="fitXY" />

now I just want to set the imageview to be a static color, like red or green. I'm trying:

ColorDrawable cd = new ColorDrawable("FF0000");
cd.setAlpha(255);
ImageView iv = ...;
iv.setImageDrawable(cd);

the imageview is just empty though, no color. The 45dip space is being used up though. What do I need to do to get the color to be rendered?

Thanks

© Stack Overflow or respective owner

Related posts about android

Related posts about android-sdk