到目前为止,我知道如何通过 html 代码更改背景的颜色。现在,我正在尝试使用单击按钮将主要 Activity 的布局背景更改为不同的图像。如果可能,只使用一个按钮。
谢谢!
最佳答案
以下代码来自此链接Setting background image in java来自 Omi0301。
//assuming your Layout is named linearlayout1:
LinearLayout ll = (LinearLayout) findViewById(R.id.linearlayout1);
ll.setBackgroundResource(R.drawable.sample);
您所要做的就是创建一个布局变量并使用您希望的图像设置其背景资源。
关于java - Android Studio : How to change the Background to jpg. 图像使用 OnclickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24398569/