【问题标题】:Change the color of Checkbox更改复选框的颜色
【发布时间】:2017-11-25 02:08:44
【问题描述】:

我想更改复选框边框颜色的颜色,但我需要以编程方式进行。

这是我的代码

    if (Build.VERSION.SDK_INT < 21) {
        //The issue is here
        CompoundButtonCompat.setButtonTintList(holder.checkbox, ColorStateList.valueOf(this.currentThemeOptions.modalFormsTextColor));
    } else {
        //This works just fine
        holder.checkbox.setButtonTintList(ColorStateList.valueOf(this.currentThemeOptions.modalFormsTextColor));
    }

您对在 低于 API 21 的 Android API 中更改复选框的边框颜色有何建议?

【问题讨论】:

  • @SahilManchanda 我需要以编程方式完成此操作。
  • 使您的 chechbox 支持复选框 android.support.v7.widget.AppCompatCheckBox
  • 谢谢@Bek。它适用于 API
  • @Emre rica ederim

标签: android checkbox android-checkbox


【解决方案1】:

这是我之前用于具有可自定义 UI 的应用的解决方案:

AppCompatCheckBox box = new AppCompatCheckBox(activity);
box.setText("Checkbox");
ColorStateList colorStateList = new ColorStateList(
                    new int[][] {
                            new int[] { -android.R.attr.state_checked }, // unchecked border color
                            new int[] {  android.R.attr.state_checked }  // checked color
                    },
                    new int[] {
                            Color.BLACK,
                            Color.WHITE
                    }
            );
box.setSupportButtonTintList(colorStateList);
box.setTextColor(Color.BLACK);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 1970-01-01
    • 2020-09-21
    • 2018-04-24
    • 2016-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多