Switch

Switches allow users to toggle between two states, on or off. On mobile, these are often used as a replacement for checkboxes.

Switch

Maven Central Class reference Source code

Default

Day Night
Switch component Switch component - dark mode

Installation

Backpack Android is available through Maven Central. Check the main Readme for a complete installation guide.

Usage

The Switch component can be used in both XML and Kotlin/Java

Example of a switch in XML


                                                
                                                <net.skyscanner.backpack.toggle.BpkSwitch
                                                  android:layout_width="wrap_content"
                                                  android:layout_height="wrap_content"
                                                  android:checked="true" />

Example of a switch in Kotlin


                                                
                                                import net.skyscanner.backpack.toggle.BpkSwitch
                                                
                                                BpkSwitch(context).apply {
                                                  isChecked = true
                                                }

Theme Props

  • switchPrimaryColor

Styles can be changed globally through bpkSwitchStyle. Check theming for more information.