在v21之前的Tinting复选框 [英] Tinting Checkbox on pre v21
问题描述
所以,我想对AppCompat复选框应用色调。
So, I want to apply tint to AppCompat Checkbox.
在Lollipop上一切正常:
Everything works fine on Lollipop:
android:buttonTint="@color/purple_FF4081"
方式:
android:theme="@style/Theme.MyTheme.PurpleAccent"
但是设置这些参数不会改变前Lollipop的任何东西。仅适用于为应用程序主题设置 colorAccent
的情况。但我不想让所有的小部件改变他们的外观,只是一个复选框。
有没有办法做到这一点,而不设置彩色drawables?
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?
推荐答案
快速fyi,引入AppCompatActivity和新的支持库,供参考(在此处概述)复选框可以通过使用主题
atttribute并设置 colorControlNormal
和 colorControlActivated
:
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
styles.xml
<style name="MyCheckBox" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item>
</style>
layout xml:
layout xml:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Check Box"
android:theme="@style/MyCheckBox"/>
这篇关于在v21之前的Tinting复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!