Skip to content

BlurSwitchButtonView

Use Component

xml
<com.qmdeve.blurview.widget.BlurSwitchButtonView
    android:layout_width="65dp"
    android:layout_height="wrap_content"
    app:baseColor="#0161F2"
    app:useSolidColorMode="false" />
java
BlurSwitchButtonView blurSwitch = new BlurSwitchButtonView(context);
blurSwitch.setBaseColor(0xFF0161F2);
blurSwitch.setChecked(true, true);
blurSwitch.setOnCheckedChangeListener(isChecked -> {
    // Handle state change
});
kotlin
val blurSwitch = BlurSwitchButtonView(context)
blurSwitch.setBaseColor(0xFF0161F2.toInt())
blurSwitch.setChecked(true, true)
blurSwitch.setOnCheckedChangeListener { isChecked ->
    // Handle state change
}

Attribute Description

Attribute NameTypeDefault ValueDescription
app:baseColorcolor#0161F2Base color used to derive on/off track colors.
app:useSolidColorModebooleanfalseEnable solid color mode instead of blur-derived track colors.
app:solidOnColorcolorauto-generatedExplicit ON color used in solid color mode.
app:solidOffColorcolorauto-generatedExplicit OFF color used in solid color mode.

API Reference

MethodDescription
setOnCheckedChangeListener(OnCheckedChangeListener)Listen for checked state changes.
toggle()Toggle current checked state with animation.
isChecked()Get checked state.
setChecked(boolean, boolean)Set checked state with optional animation.
setBaseColor(int)Set base color and regenerate track colors.
setUseSolidColorMode(boolean)Enable or disable solid color mode.
isUseSolidColorMode()Get current solid color mode state.
setSolidColors(int, int)Set explicit ON/OFF colors for solid mode.
getSolidOnColor()Get current solid ON color.
getSolidOffColor()Get current solid OFF color.

WARNING

For most use cases, setting only app:baseColor is enough. The view can derive ON/OFF colors automatically.