xamarin 如何更改复选框中复选标记和边框的颜色

atmip9wb  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(167)

"想做什么"
我想用4 patterns创建复选框为了实现这个,我想知道:
①如何改变支票的颜色。
②如何改变复选框边框的颜色。
我已经尝试过这个代码,并改变了背景的颜色。但它不足以实现我想要的。

//change the color of background in a checkbox
android:buttonTint="#ffffff"
sulc1iza

sulc1iza1#

In general, you can use property android:button to achieve this.
Please refer to the following code:
1.create a xml file checkbox_background.xml in folder drawable

<?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/checked" />
      <item android:state_checked="false"
            android:drawable="@drawable/unchecked" />
</selector>

2.set the android:button property of CheckBox to checkbox_background :

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

Note: You can also set other status of checkbox in the item of selector .

ttvkxqim

ttvkxqim2#

您需要手动定义XML中的各种属性,下面是一个示例--您需要根据您的特定用例修改它:

<CheckBox
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:button="@null"
            android:id="@+id/checkbox"
            android:background="?android:attr/listChoiceIndicatorMultiple"
            android:colorAccent="@color/checkboxcolor"
            android:buttonTint="@color/checkboxcolor" />

当然,你可以把android:background改成其他的东西。还要注意android:button可以是任何可绘制的,但我没有使用它,然后把它设置为@null。所以你应该能够通过使用这些xml属性来达到你想要的结果,比如background(任何可绘制的--这里我只是使用了一个来自android的内置可绘制的,但你也可以使用你自己的可绘制的。如果你愿意,你可以在自定义的可绘制的里面定义一个边框。

相关问题