HarmonyOS Toggle绑定onChange事件设置APP深色模式无效

Toggle绑定onChange事件设置是否深色模式无效,使用按钮或者图片设置点击事件调同一个方法就有效。

HarmonyOS
2024-10-10 10:48:47
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

参考demo:

import { ConfigurationConstant } from '@kit.AbilityKit';  
@Entry  
@Component  
struct ToggleExample {  
 @Watch('changeColorMode') @State isOn:boolean = false  
  build() {  
    Column() {  
      Row() {  
        Toggle({ type: ToggleType.Switch,isOn:this.isOn })  
          .margin({left: 200, right: 10})  
          .onChange(()=>{  
            this.isOn = !this.isOn  
          })  
      }  
    }  
  }  
  changeColorMode(){  
    let context = getContext(this).getApplicationContext()  
    context.setColorMode(this.isOn? ConfigurationConstant.ColorMode.COLOR_MODE_DARK:ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT)  
  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
分享
微博
QQ
微信
回复
2024-10-10 18:06:18
相关问题
app适配深色浅色切换模式
2654浏览 • 1回复 待解决
HarmonyOS Toggle组件onChange方法手动触发
1133浏览 • 1回复 待解决
HarmonyOS app内如何禁用深色模式
932浏览 • 1回复 待解决
HarmonyOS 深色模式
1039浏览 • 1回复 待解决
HarmonyOS 浅色模式深色模式
928浏览 • 1回复 待解决
如何设置Web组件的深色模式
1077浏览 • 1回复 待解决
HarmonyOS TextInput双向绑定无效
763浏览 • 1回复 待解决
HarmonyOS web深色模式
711浏览 • 1回复 待解决
如何将页面设置深色模式
3056浏览 • 1回复 待解决
HarmonyOS 如何禁用深色模式
617浏览 • 1回复 待解决
应用如何适配深色模式
2318浏览 • 1回复 待解决
HarmonyOS 如何禁止深色模式使用
794浏览 • 1回复 待解决
应用如何适配深色模式
3485浏览 • 1回复 待解决