Android主题更改复选框项目文本颜色 [英] Android themes change checkbox item text color

查看:563
本文介绍了Android主题更改复选框项目文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅更改Android Studio的styles.xml中复选框视图的文本颜色?

How do I just change the text color of checkbox views in Android Studio's styles.xml?

我想创建一个主题,其中所有复选框项的颜色都不同于默认的黑色,例如:

I want to create a theme where all checkbox items are a color different from the default black like:

除了我希望框本身与文本具有相同的颜色.

Except I want the box itself to be the same color as the text.

我应该在主题中使用以下内容吗?

Should I be using the following in my theme?

<item name="android:checkboxStyle">@style/App_CheckboxStyle</item>

推荐答案

我知道这个问题是很久以前提出的,但是我想添加我的解决方案.它适用于所有SDK版本.

I know that this question is asked long time ago but I want to add my solution. It works with all SDK versions.

您是正确的,为了在整个项目中更改CheckBox样式,您必须在主题中添加以下行:

You are right that in order to change CheckBox style in the whole project, you have to add the line to your theme:

<style name="AppTheme" parent="Theme.AppCompat">
    ...
    <item name="android:checkboxStyle">@style/MyCheckBoxStyle</item>
    ...
</style>

样式本身,您可以在其中设置自定义文本和复选框的颜色:

And the style itself, where you set your custom text and checkbox color:

<style name="MyCheckBoxStyle" parent="Widget.AppCompat.CompoundButton.CheckBox">
    <item name="android:textColor">@android:color/holo_purple</item>
    <item name="buttonTint">@android:color/holo_purple</item>
</style>

注意:前缀android:表示属性已链接到SDK属性.如果删除它,该属性将链接到支持库.这就是系统将buttonTintandroid:buttonTint视为不同参数的原因.如果您的最低SDK为21,则无需使用支持库,而只需使用android:buttonTint.

Note: android: prefix indicates that a property is linked to SDK attributes. If you remove it, the property links to support library. That's why system treats buttonTint and android:buttonTint as different parameters. If your minimum SDK is 21, you don't need to use support library and you can simply use android:buttonTint.

这篇关于Android主题更改复选框项目文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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