HarmonyOS 如何获取当前是否为深色模式

需要根据当前是否为深色模式设置不同的颜色。

HarmonyOS
2024-12-25 10:42:29
702浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

a等于0时为深色,1时为浅色,可以参考下面demo:

import { common, ConfigurationConstant } from '@kit.AbilityKit';

@Entry
@Component
struct Page7235 {
  @State message: string = 'Hello World';

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('Page7235HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .onClick(() => {
          let context = getContext(this) as common.UIAbilityContext
          let a: ConfigurationConstant.ColorMode | undefined = context.config.colorMode
          console.log(a?.toString())
        })
    }
    .height('100%')
    .width('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-app-ability-configuration-V5#%E5%B1%9E%E6%80%A7

分享
微博
QQ
微信
回复
2024-12-25 13:28:10
相关问题
鸿蒙怎么获取当前是不是深色模式
9337浏览 • 1回复 待解决
如何将页面设置深色模式
3053浏览 • 1回复 待解决
HarmonyOS 深色模式
1026浏览 • 1回复 待解决
HarmonyOS 浅色模式深色模式
904浏览 • 1回复 待解决
HarmonyOS 如何禁用深色模式
604浏览 • 1回复 待解决
应用如何适配深色模式
2286浏览 • 1回复 待解决
HarmonyOS 如何禁止深色模式使用
784浏览 • 1回复 待解决
应用如何适配深色模式
3448浏览 • 1回复 待解决
HarmonyOS web深色模式
700浏览 • 1回复 待解决
HarmonyOS app内如何禁用深色模式
927浏览 • 1回复 待解决
HarmonyOS web组件获取title当前链接
1070浏览 • 1回复 待解决
深色模式如何屏蔽?有人知道吗?
1009浏览 • 0回复 待解决
如何设置Web组件的深色模式
1077浏览 • 1回复 待解决