您的位置:首页 > 移动开发 > Android开发

android Button 颜色的变化(点击,放开,点击不放)

2013-11-07 10:48 507 查看
参考:
http://endual.iteye.com/blog/1534258
总结:

定义res/drawable/button_style.xml文件

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
	<item android:state_pressed="true" android:drawable="@drawable/play_press" />
<item android:state_focused="true" android:drawable="@drawable/play_press" />
<item android:drawable="@drawable/play" />
</selector>


以上需要放两种图片,play_press.png和play.png

也可以直接使用颜色:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">  
<item android:state_pressed="true" android:drawable="@color/chocolate" />
<item android:state_focused="true" android:drawable="@color/darkslategray" />
<item android:drawable="@color/tan" /> 
</selector>


使用style文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/hello" />
<Button android:id="@+id/button1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/button_style"
></Button>
</LinearLayout>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: