参考demo如下:@Entry @Component struct ToggleExample { @State is_on:boolean = false; build() { Column() { Row() { Text("Bluetooth Mode") .height(50) .fontSize(16) } Row() { Text("Bluetooth") .height(50) .padding({left: 10}) .fontSize(16) .textAlign(TextAlign.Start) .backgroundColor(0xFFFFFF) Stack(){ Toggle({ type: ToggleType.Switch ,isOn:this.is_on}) .margin({left: 200, right: 10}) Column(){ }.width(60) .height(50) .margin({left: 200, right: 10}) .onClick(()=>{ this.is_on = !this.is_on }) } } .backgroundColor(0xFFFFFF) } .padding(10) .backgroundColor(0xDCDCDC) .width('100%') .height('100%') } }
参考demo如下: