All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.com.sceyt.chatuikit.presentation.custom_views.CircleCheckBox.kt Maven / Gradle / Ivy

There is a newer version: 1.7.2
Show newest version
package com.sceyt.chatuikit.presentation.custom_views

import android.content.Context
import android.graphics.drawable.StateListDrawable
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatCheckBox
import com.sceyt.chatuikit.styles.common.CheckboxStyle

class CircleCheckBox @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0
) : AppCompatCheckBox(context, attrs, defStyleAttr) {

    fun applyStyle(checkboxStyle: CheckboxStyle) {
        val pressedState = android.R.attr.state_pressed
        val checkedState = android.R.attr.state_checked
        buttonDrawable = StateListDrawable().apply {
            // Checked state
            addState(intArrayOf(checkedState), checkboxStyle.checkedIcon)
            // Pressed state
            addState(intArrayOf(pressedState), checkboxStyle.pressedIcon)
            // Unchecked state
            addState(intArrayOf(-pressedState), checkboxStyle.uncheckedIcon)
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy