Android Styling CheckBox

In the previous tutorial we have seen basic example checkbox .

In this tutorials we will see styling of checkbox .


ColorAccent


To Change CheckBox Tick Mark Color everywhere in your entire application , then change the colorAccent color of BaseTheme in style.xml

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
 <!-- Customize your theme here. -->
 <item name="colorPrimary">@color/colorPrimary</item>
 <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
 <item name="colorAccent">@color/colorAccent</item>
</style>


Theme For Particular Checkbox


 If you want to style particular checkbox then create  your own style and extend it to @style/Widget.AppCompat.CompoundButton.CheckBox .

  1.  colorControlNormal : controls the ‘normal’ state of components such as an unselected EditText, and unselected Checkboxes and RadioButtons
  2.  colorControlActivated : overrides colorAccent as the activated or checked state for Checkboxes and RadioButtons
  3.  colorControlHighlight : controls the ripple coloring .
<style name="CustomCheckbox01" parent="@style/Widget.AppCompat.CompoundButton.CheckBox">
 <item name="android:colorControlNormal">#7a7a7a</item>
 <item name="android:colorControlActivated">#3db5ea</item>
 <item name="android:colorControlHighlight">#3db5ea</item>
</style>


android:theme attribute of checkbox is used to add above defined theme

<CheckBox
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:id="@+id/checkbox02"
 android:text="checkbox 02"
 android:theme="@style/CustomCheckbox01"/>


No comments:

Post a Comment