读书人

旋钮的多样话 selector的使用

发布时间: 2012-09-06 10:37:01 作者: rapoo

按钮的多样话 selector的使用

<?xml version="1.0" encoding="utf-8"?>
?<selector xmlns:android="http://schemas.android.com/apk/res/android">
? ? ?<item android:drawable="@drawable/button_normal" /> <!-- default -->
? ? ?<item android:state_pressed="true"
? ? ? ? ? ?android:drawable="@drawable/button_pressed" /> <!-- pressed -->
? ? ?<item android:state_focused="true"
? ? ? ? ? ?android:drawable="@drawable/button_focused" /> <!-- focused -->
?</selector>

?

?XML file in your project res/drawable/ folder?

引用 ImageButton ( android:src attribute).

http://developer.android.com/intl/de/reference/android/widget/ImageButton.html

?

http://developer.android.com/intl/fr/reference/android/graphics/drawable/StateListDrawable.html

?styles 不能代码修改 theme可以动态修改

http://developer.android.com/intl/fr/guide/topics/ui/themes.html

res/drawable/my_button.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/btn_pressed" />?
? <item?
? ? android:state_pressed="false"?
? ? android:drawable="@drawable/btn_normal" />?
</selector>?
Button如此设置android:background="@drawable/my_button".

1 楼 lattimore 2010-12-30 有没有搞错!?

读书人网 >移动开发

热点推荐