jeudi 22 janvier 2015

How to override CheckBox color using AppCompat

When my checkbox is checked, I want the color to be @color/colorPrimaryLight. I can set it that way for Lollipop by setting



android:buttonTint="@color/colorPrimaryLight"


in the CheckBox but I don't know how to do it for anything before Lollipop without changing



<item name="colorControlActivated">@color/white</item>


in my theme.


CheckBox for Lollipop:



<CheckBox
android:buttonTint="@color/colorPrimaryLight"
android:id="@+id/SwapCheckbox"
android:layout_marginTop="@dimen/margin_top"
android:layout_marginLeft="@dimen/margin_left_right"
android:layout_marginRight="@dimen/margin_left_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


and for anything before Lollipop (and higher than 4.0.3):



<CheckBox
android:id="@+id/SwapCheckbox"
android:layout_marginTop="@dimen/margin_top"
android:layout_marginLeft="@dimen/margin_left_right"
android:layout_marginRight="@dimen/margin_left_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


And I also have in the theme for my app:



<style name="AppTheme" parent="Theme.AppCompat.Light">
//...
<item name="colorControlActivated">@color/white</item>
//...
</style>


I can't change colorControlActivated as it must be white for the indicator in my ViewPager. Is there anyway to change the background color of my checkbox (even if it is to the default Holo style however best so that it is set to @color/colorPrimaryLight)?





Aucun commentaire:

Enregistrer un commentaire