1 2# Switch (lv_switch) 3 4## Overview 5 6The Switch looks like a little slider and can be used to turn something on and off. 7 8 9## Parts and Styles 10- `LV_PART_MAIN` The background of the switch uses all the typical background style properties. `padding` makes the indicator smaller in the respective direction. 11- `LV_PART_INDICATOR` The indicator that shows the current state of the switch. Also uses all the typical background style properties. 12- `LV_PART_KNOB` A rectangle (or circle) drawn at left or right side of the indicator. Also uses all the typical background properties to describe the knob(s). By default, the knob is square (with an optional corner radius) with side length equal to the smaller side of the slider. The knob can be made larger with the `padding` values. Padding values can be asymmetric too. 13 14## Usage 15 16### Change state 17The switch uses the standard `LV_STATE_CHECKED` state. 18 19To get the current state of the switch (with `true` being on), use `lv_obj_has_state(switch, LV_STATE_CHECKED)`. 20 21Call `lv_obj_add_state(switch, LV_STATE_CHECKED)` to turn it on, or `lv_obj_clear_state(switch, LV_STATE_CHECKED)` to turn it off. 22 23 24## Events 25- `LV_EVENT_VALUE_CHANGED` Sent when the switch changes state. 26 27See the events of the [Base object](/widgets/obj) too. 28 29Learn more about [Events](/overview/event). 30 31## Keys 32- `LV_KEY_UP/RIGHT` Turns on the slider 33- `LV_KEY_DOWN/LEFT` Turns off the slider 34- `LV_KEY_ENTER` Toggles the switch 35 36Learn more about [Keys](/overview/indev). 37 38## Example 39 40```eval_rst 41 42.. include:: ../../../examples/widgets/switch/index.rst 43 44``` 45 46## API 47 48```eval_rst 49 50.. doxygenfile:: lv_switch.h 51 :project: lvgl 52 53``` 54