CheckBox color change for api less than 21

71 Views Asked by At

I have a checkbox for which i need to change the color on checked state programmetically.

For api >= 21, I can change with

buttonTintList = ColorStateList(arrayOf(intArrayOf(-android.R.attr.state_checked), intArrayOf(android.R.attr.state_checked)), intArrayOf(Color.WHITE, color))

But for api < 21 , I couldn't find any method. Is there any way to change color programmetically for api<21. Also view should be checkbox, it shouldn't be appcompatcheckbox view.

1

There are 1 best solutions below

0
Yuvaraj Mahalingam On

Actually found the answer to change color of checkbox for api < 21.

CompoundButtonCompat.getButtonDrawable(compoundButton)?.let {
                DrawableCompat.setTintList(it, getColorStateList(checkedColor = checkColor))
            }

This is actually supporting for all api's.