#鸿蒙通关秘籍#如何设置应用局部页面自定义主题风格,并同时可配置子组件深浅色模式?

HarmonyOS
2024-12-06 13:57:36
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
CodeNinja

啥都不说了,我直接上码:

@Entry
@Component
struct Index {
build() {
Column() {
Column() {
Text('无WithTheme')
.fontSize(40)
.fontWeight(FontWeight.Bold)
}
.justifyContent(FlexAlign.Center)
.width('100%')
.height('33%')
.backgroundColor($r('sys.color.background_primary'))

WithTheme({ colorMode: ThemeColorMode.DARK }) {
Column() {
Text('WithTheme')
.fontSize(40)
.fontWeight(FontWeight.Bold)
Text('DARK')
.fontSize(40)
.fontWeight(FontWeight.Bold)
}
.justifyContent(FlexAlign.Center)
.width('100%')
.height('33%')
.backgroundColor($r('sys.color.background_primary'))
}

WithTheme({ colorMode: ThemeColorMode.LIGHT }) {
Column() {
Text('WithTheme')
.fontSize(40)
.fontWeight(FontWeight.Bold)
Text('LIGHT')
.fontSize(40)
.fontWeight(FontWeight.Bold)
}
.justifyContent(FlexAlign.Center)
.width('100%')
.height('33%')
.backgroundColor($r('sys.color.background_primary'))
}
}
.height('100%')
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.END, SafeAreaEdge.BOTTOM, SafeAreaEdge.START])
}
}
  • 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.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
已于2024-12-18 10:15:06修改
分享
微博
QQ
微信
回复
2024-12-06 16:56:18
相关问题
HarmonyOS 主动设置深浅色模式
847浏览 • 1回复 待解决
HarmonyOS 如何监听深浅色模式
675浏览 • 1回复 待解决
HarmonyOS 浅色深色主题如何设置
1274浏览 • 1回复 待解决
HarmonyOS 如何自定义picker主题
1054浏览 • 1回复 待解决