【发布时间】:2012-04-18 17:48:06
【问题描述】:
我想为 ImageView 设置背景颜色,当 imageview 有图像资源时,它可以工作并且我得到我的背景颜色,但是当图像视图没有图像资源时,SetBackgroundColor 不起作用并且什么都不做,这是我的代码:
xml 布局:
<ImageView android:layout_centerHorizontal="true"
android:id="@+id/favor_item_image"
android:layout_alignParentTop="true" android:layout_height="wrap_content"
android:layout_width="match_parent" android:adjustViewBounds="true"/>
java代码:
ImageView favorImage = (ImageView) MyView.findViewById(R.id.favor_item_image);
//favorImage.setImageResource(R.drawable.btndelete);
favorImage.setBackgroundColor(Color.argb(255,255,0,0));
所以,当我评论这一行时: //favorImage.setImageResource(R.drawable.btndelete);我无法设置图像视图背景颜色,但是当我取消注释此行时,setBackgroundColor 工作正常。
请帮忙。 谢谢
【问题讨论】:
标签: android android-imageview setbackground