bluebyte bluebyte - 5 months ago 58
Android Question

Tinting Checkbox on pre v21

So, I want to apply tint to AppCompat Checkbox.

Everything works fine on Lollipop:

android:buttonTint="@color/purple_FF4081"


or this way:

android:theme="@style/Theme.MyTheme.PurpleAccent"


But setting any of this params do not change anything on pre-Lollipop. Works only if I set
colorAccent
for the app theme. But I don't want all widgets to change their look, just one checkbox.
Is there any way to do this without setting colored drawables?

Answer

Quick fyi that this has all changed now after the introduction of the AppCompatActivity and the new support libraries, for reference (outlined beautifully here) a checkbox can be tinted by using the theme atttribute and setting the colorControlNormal and colorControlActivated:

styles.xml

<style name="MyCheckBox" parent="Theme.AppCompat.Light">  
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item>
</style> 

layout xml:

<CheckBox  
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"
        android:text="Check Box"
        android:theme="@style/MyCheckBox"/>