When using a custom checkbox or RadioButton, the custom icons and text appear on different phones with different spacing, sometimes less control, and here's My custom checkbox:
XML under Layout:
<checkbox android:id= "@+id/recharge_activity_cb" style= "@style/customcheckboxtheme" android: Layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "I have read and agree" Android: Textcolor= "@color/huoqiulightblackcolor" android:checked= "true" />
Inside the custom Style,style content is:
<!--custom checkbox-- <style name= "Customcheckboxtheme" parent= "@android: style/ Widget.CompoundButton.CheckBox "> <item name=" Android:button "> @drawable/checkbox_style</item> <item name= "Android:paddingleft" > @dimen/dp8</item> </style>
The selected and unchecked pictures are called, under drawable:
<?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/agree "/> <item Android:state_checked= "false" android:drawable= "@drawable/disagree"/> <item android:drawable= "@ Drawable/disagree "/></selector>
Although you can display the desired on some systems by setting paddingleft, some do not.
<item name= "Android:paddingleft" > @dimen/dp8</item>
So the question is, in what way can we solve it?
Here's my solution: using the Checkedtextview control
<checkedtextview android:id= "@+id/recharge_activity_ctv" android:checkmark= "@drawable/checkbox_ Style " android:layout_width=" wrap_content " android:layout_height=" wrap_content " android:checked=" True " />
<textview android:id= "@+id/buy_write_jine_agree_tv" android:layout_width= "Wrap_content" Android : layout_height= "wrap_content" android:text= "I have read and agree to" android:textcolor= "@color/huoqiulightblackcolor" android:layout_marginleft= "@dimen/dp3" />
Where checkmark is the top drawable. The selected state XML
android:checkmark= "@drawable/checkbox_style"
Then use ischecked () in the code to determine whether the Checkedtextview is selected, use the toggle () method to set the check and uncheck the effect, so there is no space between the icon and the text, the problem is solved perfectly!
Android CheckBox RadioButton picture and text spacing issues