v21 之前的着色复选框 [英] Tinting Checkbox on pre v21
问题描述
所以,我想对 AppCompat Checkbox 应用色调.
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"
但是设置这些参数中的任何一个都不会改变 pre-Lollipop 的任何内容.仅当我为应用主题设置 colorAccent
时才有效.但我不希望所有小部件都改变它们的外观,只需要一个复选框.有没有办法在不设置彩色可绘制对象的情况下做到这一点?
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?
推荐答案
快速了解一下,在引入 AppCompatActivity 和新的支持库 供参考(此处概述得很漂亮) 可以通过使用 theme
属性并设置 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
<style name="MyCheckBox" parent="Theme.AppCompat.Light">
<item name="colorControlNormal">@color/indigo</item>
<item name="colorControlActivated">@color/pink</item>
</style>
布局xml:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Check Box"
android:theme="@style/MyCheckBox"/>
这篇关于v21 之前的着色复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!