如何设置ImageButton的背景图片?
我尝试使用以下代码使 ImageButton 不可见,但单击它没有执行任何操作。换句话说,它应该调用的方法没有执行任何操作(它应该使用 setImageResource 函数更改图像)。
die1button.setBackgroundColor(android.R.color.transparent);
那么,如何在 Java 中更改背景图像,或者使其完全清晰,同时仍然允许按钮工作?我更愿意更改图像,但我还没有弄清楚如何做到这一点。
I tried to use the following code to make my ImageButton invisible, but clicking it did not do anything. In other words, the method that it was supposed to call did not do anything (it is supposed to change the image using the setImageResource
function).
die1button.setBackgroundColor(android.R.color.transparent);
So, how can I change the background image in Java, or make it completely clear, while still allowing the button to work? I would prefer to change the image, but I have not figured out how to do that yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想通了。
我想我只是想得还不够。我仍然希望听到任何更好的方法来做到这一点。
I figured it out.
I guess I just wasn't quite thinking enough. I would still like of hear of any better ways to do this.
我会在 xml 文件中设置图像。
I would set the image in the xml file.