【问题标题】:Android Get the Background Ressource of an ImageButtonAndroid 获取 ImageButton 的背景资源
【发布时间】:2013-04-21 11:50:51
【问题描述】:

我需要获取一些 ImageButton 的背景资源,以便稍后重新使用它,设置背景我使用 setBackgroundResource。我没有找到任何获取背景资源的方法。

private void AddImage(int img){
    ImageButton imgact1 = (ImageButton)findViewById(R.id.imgact1);
    ImageButton imgact2 = (ImageButton)findViewById(R.id.imgact2);
    ImageButton imgact3 = (ImageButton)findViewById(R.id.imgact3);
    imgact3.setBackgroundResource(img);
}

感谢您的帮助。

【问题讨论】:

标签: java android image background imagebutton


【解决方案1】:

对于任何View,您应该使用getBackground(),它返回一个Drawable

【讨论】:

  • @Da-monk,不客气。如果您发现它有帮助,请不要忘记接受答案。
  • 我如何将该值存储在字符串中?如果图像是在android:src 中定义的,我可以这样做吗?谢谢! PS:我已经投票了
  • 这是因为我正在尝试比较值。例如:如果图像是red circle,那么执行此操作,如果图像是blue circle,则执行此操作
  • 我试过if(buttonBackground.equals(@drawable/mydrawable)),但它不起作用。那是Drawable buttonBackground = myButton.getBackground();
猜你喜欢
  • 1970-01-01
  • 2012-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多