Skip to main content
Version: v3

SLIDE_SWITCH

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

slide_switch_sample

Used to switch between open and closed states.

Create UI widget

import { createWidget, widget } from '@zos/ui'

const slideSwitch = createWidget(widget.SLIDE_SWITCH, Param)

Type

Param: object

PropertiesDescriptionRequiredType
xThe x-axis coordinate of the widget.YESnumber
yThe y-axis coordinate of the widget.YESnumber
wThe width of the widget.YESnumber
hThe height of the widget.YESnumber
select_bgThe selected background.YESstring
un_select_bgUnselected background.YESstring
slide_srcSwitch button.YESstring
slide_select_xThe selected state of the switch button.(relative to x-coordinate)YESnumber
slide_un_select_xThe unselected state of the switch button.(relative to x-coordinate)YESnumber
slide_yThe y-axis offset of the switch button, relative to the coordinateNOnumber
checked_change_funcCallback on state change.NOCheckedChangeFunc
checkedDefault switch state.NOboolean

CheckedChangeFunc: function

(slideSwitch: SlideSwitch, checked: boolean) => void
ParametersDescriptionType
slideSwitchThe instance of slideSwitchSlideSwitch
checkedchecked or uncheckedboolean

Prop Properties

propertiesdescriptionsupport get/settypes
prop.CHECKEDSet switch state.Get switch stateset/getboolean returns bool type when you get

Code example

tip

Please refer to Design Resources for the image resources in the code example

import { createWidget, widget, prop } from '@zos/ui'

Page({
build() {
const slide_switch = createWidget(widget.SLIDE_SWITCH, {
x: 200,
y: 200,
w: 96,
h: 64,
select_bg: 'switch_on.png',
un_select_bg: 'switch_off.png',
slide_src: 'radio_select.png',
slide_select_x: 40,
slide_un_select_x: 8,
checked: true,
checked_change_func: (slideSwitch, checked) => {
console.log('checked', checked)
}
})

console.log('slide checked', slide_switch.getProperty(prop.CHECKED))
}
})