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

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])
}
}
已于2024-12-18 10:15:06修改
分享
微博
QQ
微信
回复
2024-12-06 16:56:18
相关问题
HarmonyOS 主动设置深浅色模式
177浏览 • 1回复 待解决
HarmonyOS 如何监听深浅色模式
116浏览 • 1回复 待解决
HarmonyOS 浅色深色主题如何设置
635浏览 • 1回复 待解决
HarmonyOS 如何自定义picker主题
194浏览 • 1回复 待解决