我有什么:: 我有一个图像视图,下面附有背景可绘制的
<ImageView
android:id="@+id/myId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/plus" />
我想要找到的内容:: 如果该imageview对象附加了背景可绘制,我如何以编程方式检查
答案 0 :(得分:2)
我相信getBackground()
方法就是你想要的。你投了票,因为这是一个微不足道的问题。
ImageView yourImageView = findViewById(R.id.myId);
Drawable background = yourImageView.getBackground();
if(background != null)
System.out.println("View has background!");
else
System.out.println("View has no background!");
答案 1 :(得分:0)
ImageView myimage = (ImageView) v.findViewById(R.id.img_call_icon);
myimage.setTag(R.drawable.myicon);
myimage.setBackgroundResource(R.drawable.myicon);
myimage.
Object tag = myimage.getTag();
int id = tag == null ? -1 : (int) tag;
switch (id) {
case R.drawable.icon:
Toast.makeText(mContext, "skype", Toast.LENGTH_SHORT).show();
break;
case R.drawable.myicon:
Toast.makeText(mContext, "call", Toast.LENGTH_SHORT).show();
break;
}