0

I want to change the color of checkbox border color but I need to do this programmatically.

Here is my code

    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));
    }

What do you suggest about changing border color of a checkbox in an Android API lower than API 21 ?

Emre Alparslan
  • 1,022
  • 1
  • 18
  • 30

1 Answers1

0

Here's a solution I've used for apps before that have a customizable 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);
widavies
  • 774
  • 2
  • 9
  • 22