您的位置:首页 > 其它

用xml文件设置ImageButton按下、弹起加载不同的图片 实现

2014-03-05 16:44 246 查看
java部分的代码就不贴了,只上xml文件,

方法:

1,在drawable里放三幅图片,分别是获得焦点的图片、获得焦点并按下、失去焦点并按下、自然状态(也就是失去焦点,并且没有按下)。这里你准备三个照片就中。

2,在drawable文件夹下新建个imagebutton.xml文件,里面的内容为:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item

android:state_focused="true"

android:state_pressed="false"

android:drawable="@drawable/snake"/>

<item

android:state_focused="true"

android:state_pressed="true"

android:drawable="@drawable/solitaire"/>

<item www.2cto.com

android:state_focused="false"

android:state_pressed="true"

android:drawable="@drawable/solitaire"/>

<item

android:drawable="@drawable/tunes"></item>

</selector>

3,在布局文件里引用这个xml文件:

<ImageButton

android:id="@+id/imgButton"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/image_button"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: