如何更改Android复选框的背景?

2024-03-10

我有 android checkBox 并且默认背景是透明的,我希望它是白色的,所以我使用样式:

<style name="BrandedCheckBox" parent="AppTheme">
    <item name="colorAccent">@color/cyan</item>
    <item name="colorControlNormal">@color/text_gray</item>
    <item name="colorControlActivated">@color/cyan</item>
</style>

并设置复选框主题:

<CheckBox
    android:id="@+id/check_payable"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_gravity="center"
    android:theme="@style/BrandedCheckBox"/>

But the result is this: enter image description here But I want it to to be like this: enter image description here

谁可以帮我这个事?


您可以使用机器人:按钮

   <CheckBox
       android:id="@+id/check_box"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:button="@drawable/checkbox_background" />

checkbox_background.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" 
    android:drawable="@drawable/checkbox_checked" />
<item android:state_checked="false"
    android:drawable="@drawable/checkbox_unchecked" />
</selector>

我在可绘制中使用这两个图像

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何更改Android复选框的背景? 的相关文章

随机推荐