One, checkbox custom picture problem
The results are checked when clicked, but there is no check when the finger is gone.
The code is as follows |
Copy Code |
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:state_checked= "false" android:drawable= "@drawable/checkbox_tishi"/> <item android:state_checked= "true" android:drawable= "@drawable/checkbox_tishi_select"/> </selector> |
The above writing, of course, did not work, so the search for a while, search for more than a pair of label status, but still can not be used. But the original is OK, think about it or look at the source of the good. Found in the source of more than a lot of configuration, of course, the first is all copied over. Then, streamline it appropriately. Releasing the program again immediately works. The results are as follows:
The code is as follows |
Copy Code |
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:state_checked= "true" android:state_window_focused= "false" android:drawable= "@drawable/checkbox_tishi_select"/> <item android:state_checked= "false" android:state_window_focused= "false" android:drawable= "@drawable/checkbox_tishi"/> <item android:state_checked= "true" android:state_pressed= "true" android:drawable= "@drawable/checkbox_tishi_select"/> <item android:state_checked= "false" android:state_pressed= "true" android:drawable= "@drawable/checkbox_tishi"/> <item android:state_checked= "true" android:state_focused= "true" android:drawable= "@drawable/checkbox_tishi_select"/> <item android:state_checked= "false" android:state_focused= "true" android:drawable= "@drawable/checkbox_tishi"/> <item android:state_checked= "false" android:drawable= "@drawable/checkbox_tishi"/> <item android:state_checked= "true" android:drawable= "@drawable/checkbox_tishi_select"/> </selector> |
Two, checkbox custom picture size problem
1. Create file Checkbox_selector.xml in drawable:
The code is as follows |
Copy Code |
<?xml version= "1.0" encoding= "Utf-8"?> <selector xmlns:android= "Http://schemas.android.com/apk/res/android" > <item android:state_checked= "true" android:drawable= "@drawable/checkbox_ok"/><!--settings Select a picture--> <item android:state_checked= "false" android:drawable= "@drawable/checkbox_empty"/><!--set unselected picture--> </selector>2. Create Styles.xml in values: <?xml version= "1.0" encoding= "Utf-8"?> <resources> <style name= "MyCheckBox" parent= "@android: Style/widget.compoundbutton.checkbox" > <item name= "Android:button" > @drawable/checkbox_selector</item> <item name= "Android:paddingleft" >25.0dip</item> <item name= "Android:maxheight" >10.0dip</item> </style> </resources> |
3. Add attributes to your checkbox:
code is as follows |
copy code |
< CheckBox android:id= "@+id/check" android:layout_width= "20DP" android:layout_ height= "20DP" android:layout_marginleft= "5DP" style= "@style/mycheckbox" / |