如何以编程方式更改图标?

时间:2013-01-28 09:26:53

标签: android

我将使用两个图标而不是切换按钮。我的目的是;

 If abc () == true 
          display(icon1)
 else 
          display(icon2)

如何在活动屏幕中以编程方式更改图标?

2 个答案:

答案 0 :(得分:0)

 If abc () == true 
    button.setBackgroundResource(R.drawable.icon1);
 else 
    button.setBackgroundResource(R.drawable.icon2);

答案 1 :(得分:0)

如果是ImageView,那么

ImageView img = (ImageView)findViewById(R.id.icon);
img.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.icon));

同样可以更改图标

相关问题