use the primary color at inactive checkboxes too

This commit is contained in:
tibbi 2021-11-07 19:32:06 +01:00
parent ca4aa31a89
commit cf364240ed

View file

@ -5,6 +5,8 @@ import android.content.res.ColorStateList
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatCheckBox
import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.helpers.isMarshmallowPlus
class MyAppCompatCheckbox : AppCompatCheckBox {
constructor(context: Context) : super(context)
@ -15,12 +17,17 @@ class MyAppCompatCheckbox : AppCompatCheckBox {
fun setColors(textColor: Int, accentColor: Int, backgroundColor: Int) {
setTextColor(textColor)
val colorStateList = ColorStateList(
arrayOf(intArrayOf(-android.R.attr.state_checked),
intArrayOf(android.R.attr.state_checked)
if (isMarshmallowPlus()) {
buttonDrawable?.applyColorFilter(accentColor)
} else {
val colorStateList = ColorStateList(
arrayOf(
intArrayOf(-android.R.attr.state_checked),
intArrayOf(android.R.attr.state_checked)
),
intArrayOf(context.resources.getColor(R.color.radiobutton_disabled), accentColor)
)
supportButtonTintList = colorStateList
)
supportButtonTintList = colorStateList
}
}
}