HarmonyOS Toggle如何在特定场景下禁用,即点击依旧保持false的状态,不会改变?

在多个Toggle来设置状态的情况下,如果第一个Toggle是false,则禁用第二个和第三个Toggle,即都设置成false,且点击这两个Toggle无法将false变为true

阅读 551
1 个回答

参考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%')
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进