如何使用AppCompat覆盖CheckBox颜色

3

当我的复选框被选中时,我希望它的颜色为@color/colorPrimaryLight。对于Lollipop版本,我可以通过以下方式设置:

android:buttonTint="@color/colorPrimaryLight"

在CheckBox中实现此功能,但我不知道如何在不更改任何内容的情况下在Lollipop之前的版本中实现此功能。

    <item name="colorControlActivated">@color/white</item>

在我的主题中。

卢比克版本的复选框:

<CheckBox
android:buttonTint="@color/colorPrimaryLight"
android:id="@+id/SwapCheckbox"
android:layout_marginTop="@dimen/margin_top"
android:layout_marginLeft="@dimen/margin_left_right"
android:layout_marginRight="@dimen/margin_left_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

对于Lollipop之前的版本(高于4.0.3):

<CheckBox
android:id="@+id/SwapCheckbox"
android:layout_marginTop="@dimen/margin_top"
android:layout_marginLeft="@dimen/margin_left_right"
android:layout_marginRight="@dimen/margin_left_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

我也为我的应用程序选择了主题:

<style name="AppTheme" parent="Theme.AppCompat.Light">
//...
<item name="colorControlActivated">@color/white</item>
//...
</style>

我无法更改colorControlActivated,因为我的ViewPager指示器必须是白色。是否有方法可以更改复选框的背景颜色(即使是到默认的Holo样式,但最好将其设置为@color/colorPrimaryLight)?

1个回答

8

在App兼容主题中使用以下属性,如下所示:

<style name="AppTheme" parent="Theme.AppCompat.Light">
  <item name="colorAccent">@color/colorAccent</item>
</style>

使用 android.support.v7.widget.AppCompatCheckBox 替代 CheckBox。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接