在v21之前的Tinting复选框 [英] Tinting Checkbox on pre v21

查看:140
本文介绍了在v21之前的Tinting复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想对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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆