我如何改变默认的复选框的颜色在Android? 默认情况下,复选框的颜色是绿色,我想改变这个颜色。 如果不可能,请告诉我如何做一个自定义复选框?


当前回答

buttonTint工作为我尝试

android:buttonTint=“@color/white”

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:id="@+id/agreeCheckBox"
    android:text="@string/i_agree_to_terms_s"
    android:buttonTint="@color/white"
    android:layout_below="@+id/avoid_spam_text"/>

其他回答

如果你的minSdkVersion是21+使用android:buttonTint属性来更新复选框的颜色:

<CheckBox
  ...
  android:buttonTint="@color/tint_color" />

在使用AppCompat库和支持低于21的Android版本的项目中,你可以使用buttonTint属性的compat版本:

<CheckBox
  ...
  app:buttonTint="@color/tint_color" />

在这种情况下,如果你想子类化一个CheckBox,不要忘记使用AppCompatCheckBox代替。

之前的回答:

你可以使用android:button="@drawable/your_check_drawable"属性来改变checkboxes的可绘制性。

您可以通过将<CheckBox>嵌入到<LinearLayout>中来更改它的背景颜色。然后将<LinearLayout>的背景色更改为您想要的颜色。

我建议在android中使用风格方法来配置内置的android视图,在你的项目中添加新的风格:

<style name="yourStyle" parent="Base.Theme.AppCompat">
    <item name="colorAccent">your_color</item> <!-- for uncheck state -->
    <item name="android:textColorSecondary">your color</item> <!-- for check state -->
</style>

并添加assign this style到复选框的主题: android:主题= " @style / youStyle”

希望这能有所帮助。

你可以创建自己的XML在drawable和使用这作为android:background="@drawable/your_xml"

这样你就可以给边角任何东西

<item>
    <shape>
        <gradient

            android:endColor="#fff"
            android:startColor="#fff"/>
        <corners
            android:radius="2dp"/>
        <stroke
            android:width="15dp"
            android:color="#0013669e"/>

    </shape>
</item>

在xml中添加buttonTint

<CheckBox
      android:id="@+id/chk_remember_signup"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:buttonTint="@android:color/white"
      android:text="@string/hint_chk_remember_me" />