你好,我有一个图像按钮 linearButton
,它在 XML 中设置了背景可绘制对象。我想有条件地替换代码中的背景,但它从来没有发生过!
Drawable replacer = getResources().getDrawable(R.drawable.replacementGraphic);
linearButton.setBackgroundDrawable(replacer);
这似乎是无效的,是否有一个图像按钮的“重新加载”函数,我必须在它们视觉上发生变化之前调用它?
最佳答案
invalidate()
方法将强制重绘任何 View :
Drawable replacer = getResources().getDrawable(R.drawable.replacementGraphic);
linearButton.setBackgroundDrawable(replacer);
linearButton.invalidate();
参见 here供引用。
关于Android imagebutton 以编程方式更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6751875/