【发布时间】:2012-05-15 06:21:17
【问题描述】:
我在 layout 中创建了一个 button 。在Drawable 文件夹中,我创建了一个名为btn01_state 的XML file。 btn01_state.xml 分配给我通过“android:background=@drawable/btn01_state”创建的button
现在,button 有一个默认的image img1。当我在button 上click 时,image1 更改为 img2,一旦我松开单击的鼠标按钮,image2 再次更改为 img1 .
我想要做的是,通过每一次点击来改变按钮的图像。
例如,最初 btn01 有 img01
如果 btn01 被按下==> 将 btn01 的 img 设置为 img02 并保持 img02 直到 btn01 再次被按下。现在,btn01 上面有 img02。
按下 btn01 时,将 img01 设置为 btn01。
我希望这能更清楚地说明我想要做什么。
btn_selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/android_blue"
android:state_pressed="true" />
<item android:drawable="@drawable/ic_launcher"
android:state_focused="true" />
<item android:drawable="@drawable/ic_launcher" />
main.xml
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/btn01"
android:background="@drawable/btn01_state"/>
【问题讨论】:
标签: android button imagebutton xml-drawable