14
我有一个ImageView的布局定义如下:如何将ColorDrawable与ImageView结合使用?
<ImageView
android:layout_width="45dip"
android:layout_height="45dip"
android:scaleType="fitXY" />
现在我只想设置ImageView的是一个静态的色彩,如红色或绿色。我试图:
ColorDrawable cd = new ColorDrawable("FF0000");
cd.setAlpha(255);
ImageView iv = ...;
iv.setImageDrawable(cd);
imageview只是空的,虽然没有颜色。尽管45dip空间已经用完了。我需要做什么才能让颜色呈现?
感谢
感谢我提供的颜色诠释,我用Color.parseColor(),现在它的作品。 – user246114 2010-03-31 02:17:07
如果你想通过编程方式使用带颜色的选择器(不可绘制),你可以使用:'ColorDrawable cd = new ColorDrawable(Color.parseColor(“#FFEDCACA”));' – Houcine 2013-04-03 14:58:53
对于任何寻找如何将纯色设置为可绘制的(像我一样),使用imageView.setBackgroundColor()更容易 – 2013-07-31 18:18:06