【问题标题】:how to set background image of an imageButton from java file如何从java文件设置imageButton的背景图像
【发布时间】:2016-04-16 20:16:38
【问题描述】:

我已经有一个带背景的图像按钮。当我单击图像按钮时,我希望背景更改为另一个图像。我尝试使用“//.setBackgroundResourse”,但它没有改变任何东西。请帮忙

【问题讨论】:

  • 请显示一些代码:)

标签: java android-studio android-imagebutton setbackground


【解决方案1】:

尝试在 setBackgroundResource 中使用可绘制参数

像这样:

Button myButton = (Button) View.findViewById(R.id.myButton);

myButton.setBackgroundResource(R.drawable.myBackground);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-06
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    相关资源
    最近更新 更多