Android的ImageButton的编程方式更改? [英] Android imagebutton change programmatically?

查看:118
本文介绍了Android的ImageButton的编程方式更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个ImageButton的 linearButton 有在XML背景绘制集。我希望有条件地更换code内的背景,但它从来没有发生!

Hello I have an imagebutton linearButton which has a background drawable set in the XML. I want to conditionally replace the background within the code, but it never happens!

Drawable replacer = getResources().getDrawable(R.drawable.replacementGraphic);
linearButton.setBackgroundDrawable(replacer);

这似乎是无效的,是有一个imagebuttons,我有他们改变视觉上之前所说的重装功能?

This seems to be ineffective, is there a "reload" function for a imagebuttons that I have to call before they change visually?

推荐答案

无效()方法会强迫任何视图的重绘:

The invalidate() method will force a redraw of any view:

Drawable replacer = getResources().getDrawable(R.drawable.replacementGraphic);
linearButton.setBackgroundDrawable(replacer);
linearButton.invalidate();

请参阅这里以供参考。

这篇关于Android的ImageButton的编程方式更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆