My purpose is to change the color of a button when click and my codes are
<?xml version="1.0" encoding="utf-8"?>
selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use grey -->
<item android:drawable="@drawable/btn_askering_active" android:state_selected="true" />
<!-- When not selected, use white-->
item android:drawable="@drawable/btn_askering" />
</selector>
It works but if i make a small ch开发者_StackOverflowange like below :
xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When not selected, use white-->
item android:drawable="@drawable/btn_askering" />
<!-- When selected, use grey -->
item android:drawable="@drawable/btn_askering_active" android:state_selected="true" />
</selector>
It does not work anymore.... I need some help...Any comments are welcomed here.Thanks
I think you need to mention stats in selector like pressed or focused and change image accordingly. Here i have attached sample selector file,have a look and try accordingly.
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="false"
android:drawable="@drawable/estimator_hover_new" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/estimator_hover_new" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/estimator_hover_new" />
<item android:drawable="@drawable/estimator_new" />
</selector>
All The Best....
精彩评论