Tinting Checkbox on pre v21

前端 未结 5 1172
春和景丽
春和景丽 2020-12-09 15:59

So, I want to apply tint to AppCompat Checkbox.

Everything works fine on Lollipop:

android:buttonTint=\"@color/purple_FF4081\"

or t

5条回答
  •  难免孤独
    2020-12-09 16:38

    I needed to do it programmatically, after digging for a little while I finally found this solution (tested on Kitkat & Marshmallow), I'll just post it in case it helps someone:

    public static void setAppCompatCheckBoxColors(final AppCompatCheckBox _checkbox, final int _uncheckedColor, final int _checkedColor) {
        int[][] states = new int[][]{new int[]{-android.R.attr.state_checked}, new int[]{android.R.attr.state_checked}};
        int[] colors = new int[]{_uncheckedColor, _checkedColor};
        _checkbox.setSupportButtonTintList(new ColorStateList(states, colors));
    }
    

提交回复
热议问题