【发布时间】:2014-05-13 16:53:59
【问题描述】:
我正在使用 eclipse 编写我的 android 应用程序,我想知道如何在单击按钮时更改 MainActivity 的背景图像。我有 img1.png 和 img2.png。背景当前设置在 img1.png 上,xml 代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/img1"
tools:context=".MainActivity" >
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="46dp"
android:layout_marginTop="55dp"
android:background="@android:color/transparent"
android:text="" />
</RelativeLayout>
我只是不确定我将使用什么 java 代码来更改 btn1 点击时的背景图像。
【问题讨论】:
-
对状态使用drawable
标签: java android eclipse button