主题色

  1. 创建自定义主题色
//EntryAbility.ets
class myTheme implements CustomTheme{
colors?: CustomColors

constructor(color: CustomColors) {
this.colors = color
}
}
onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
const theme = new myTheme()
ThemeControl.setDefaultTheme(theme)
//····
}
  1. 调用
//Index.ets
onWillApplyTheme(theme: Theme): void {
this.fontColor = theme.colors.fontPrimary
}
Text("Hello World")
.fontColor(this.fontColor)