动态创建的单选按钮或复选框不使用色彩强调 [英] Dynamically Created Radio Button or CheckBox does not use Color Accent

查看:881
本文介绍了动态创建的单选按钮或复选框不使用色彩强调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用V21 AppCompat我们可以通过设置自定义颜色主题,如下列:

Using v21 AppCompat we can set custom color themes like following:

<style name="Theme.MyTheme" parent="Theme.AppCompat">
    <!-- customize the color palette -->
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
</style>

不过,我有一大堆的动态创建的复选​​框和单选按钮的而不是从XML膨胀。这些动态创建的对象不继承我所指定的颜色口音。我能做些什么,以正确设置这些颜色的口音?

But I have a bunch of dynamically created checkboxes and radio buttons which are not inflated from xml. These dynamically created objects do not inherit the color accent that I have specified. What can I do to set these color accents properly?

推荐答案

您不能做任何事情除了创建布局文件与它比充气,它只是一个复选框。

You can't do anything about it other than creating a layout file with just one CheckBox in it and than inflate it.

由于开发人员网站声明:的材料为主题的设计只能使用布局充气装的意见时,适用

As the developers site stated: The material theme design can only be applied when loading views using a layout inflater.

这是因为新材料的设计挂钩下行移植到布局通胀的过程。

This is because the new material design backport hooks into the layout inflation process.

来源:的http://android-developers.blogspot.nl/2014/10/appcompat-v21-material-design-for-$p$p.html

编辑:
在新版本的AppCompat V7部件像复选框和单选22.1+可以动态创建(不再隐藏/内部API)。


In newer versions 22.1+ of AppCompat v7 widgets like CheckBox and RadioButton can be created dynamically (no longer hidden/internal API).

目前这些小部件的支持:

Currently these widgets are supported:

  • AppCompatAutoCompleteTextView
  • AppCompatButton
  • AppCompatCheckBox
  • AppCompatCheckedTextView
  • AppCompatEditText
  • AppCompatMultiAutoCompleteTextView
  • AppCompatRadioButton
  • AppCompatRatingBar
  • AppCompatSpinner
  • AppCompatTextView
  • AppCompatSeekBar(自23.1)
  • AppCompatImageButton(自23.1)
  • AppCompatImageView(自23.1)
  • AppCompatAutoCompleteTextView
  • AppCompatButton
  • AppCompatCheckBox
  • AppCompatCheckedTextView
  • AppCompatEditText
  • AppCompatMultiAutoCompleteTextView
  • AppCompatRadioButton
  • AppCompatRatingBar
  • AppCompatSpinner
  • AppCompatTextView
  • AppCompatSeekBar (since 23.1)
  • AppCompatImageButton (since 23.1)
  • AppCompatImageView (since 23.1)

这篇关于动态创建的单选按钮或复选框不使用色彩强调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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