农民 发表于 2025-1-23 13:20:21

鸿蒙UI开辟——自定义主题色

1、概述

ArkTs提供了应用内主题切换功能,支持全局主题切换,也支持局部主题切换,效果如下。本文针对主题切换做简朴介绍。

https://i-blog.csdnimg.cn/img_convert/e1b337336877c5f901ea859bacff44cc.gif
2、主题色

ArkTs提供了一套内置主题配色,有Colors对象持有,它包含了默认情况下,关于主题的基本资源枚举,枚举的key与说明如下:
brand  品牌色。warning一级警示色。alert二级提示色。confirm确认色。fontPrimary一级文本字体颜色。fontSecondary二级文本字体颜色。fontTertiary三级文本字体颜色。fontFourth四级文本字体颜色。fontEmphasize高亮字体颜色。fontOnPrimary一级文本反转颜色,用于彩色背景。fontOnSecondary二级文本反转颜色,用于彩色背景。fontOnTertiary三级文本反转颜色,用于彩色背景。fontOnFourth四级文本反转颜色,用于彩色背景。iconPrimary一级图标颜色。iconSecondary二级图标颜色。iconTertiary三级图标颜色。iconFourth四级图标颜色。iconEmphasize高亮图标颜色。iconSubEmphasize高亮辅助图标颜色。iconOnPrimary一级图标反转颜色,用于彩色背景。iconOnSecondary二级图标反转颜色,用于彩色背景。iconOnTertiary三级图标反转颜色,用于彩色背景。iconOnFourth四级图标反转颜色,用于彩色背景。backgroundPrimary一级背景颜色(实色,不透明)。backgroundSecondary二级背景颜色(实色,不透明)。backgroundTertiary三级背景颜色(实色,不透明)。backgroundFourth四级背景颜色(实色,不透明)。backgroundEmphasize高亮背景颜色(实色,不透明)。compForegroundPrimary前背景。compBackgroundPrimary白色背景。compBackgroundPrimaryTran白色透明背景。compBackgroundPrimaryContrary常亮背景。compBackgroundGray灰色背景。compBackgroundSecondary二级背景。compBackgroundTertiary三级背景。compBackgroundEmphasize高亮背景。compBackgroundNeutral黑色中性高亮背景颜色。compEmphasizeSecondary20%高亮背景颜色。compEmphasizeTertiary10%高亮背景颜色。compDivider通用分割线颜色。compCommonContrary通用反转颜色。compBackgroundFocus获焦态背景颜色。compFocusedPrimary获焦态一级反转颜色。compFocusedSecondary获焦态二级反转颜色。compFocusedTertiary获焦态三级反转颜色。interactiveHover通用悬停交互式颜色。interactivePressed通用按压交互式颜色。interactiveFocus通用获焦交互式颜色。interactiveActive通用激活交互式颜色。interactiveSelect通用选择交互式颜色。interactiveClick通用点击交互式颜色。 对应的颜色罗列如下:
Token场景类别LightDarktheme.colors.brand品牌色#ff0a59f7 https://i-blog.csdnimg.cn/img_convert/9ae7b384bf6b874318c56e8adaba21b4.png
#ff317af7 https://i-blog.csdnimg.cn/img_convert/a33ba35c739e4513fd6bad7b79c4abec.png
theme.colors.warning一级警示色#ffe84026 https://i-blog.csdnimg.cn/img_convert/f0005448835588a5478f2f6b437ef448.png
#ffd94838 https://i-blog.csdnimg.cn/img_convert/576408616f8295b2b4545d500a215722.png
theme.colors.alert二级警示色#ffed6f21 https://i-blog.csdnimg.cn/img_convert/80d0e61382bd849e3a6dc5d4be9c1f20.png
#ffdb6b42 https://i-blog.csdnimg.cn/img_convert/6cb58d7e362534015ac3c8792a5dbdc9.png
theme.colors.confirm确认色#ff64bb5c https://i-blog.csdnimg.cn/img_convert/d1d9bd248bb2c7e81e438cf23f098a2e.png
#ff5ba854 https://i-blog.csdnimg.cn/img_convert/077eaba84391a01fc6ab3f8eb2648b6a.png
theme.colors.fontPrimary一级文本#e5000000 https://i-blog.csdnimg.cn/img_convert/9b65c480031c3520fb91a7c73ba8ec43.png
#e5ffffff https://i-blog.csdnimg.cn/img_convert/611b51dd0738b769251122c0e28b67f5.png
theme.colors.fontSecondary二级文本#99000000 https://i-blog.csdnimg.cn/img_convert/03968eb8741b84015f333c795af785ca.png
#99ffffff https://i-blog.csdnimg.cn/img_convert/3209aaada33cee1051ad0c357a47f52b.png
theme.colors.fontTertiary三级文本#66000000 https://i-blog.csdnimg.cn/img_convert/56e1c1ee8615348571eaeca0f67f3b9c.png
#66ffffff https://i-blog.csdnimg.cn/img_convert/66e245a89969572a48d49d96cc7e87cd.png
theme.colors.fontFourth四级文本#33000000 https://i-blog.csdnimg.cn/img_convert/0b4cc533b2ac595a44fa0b16d04236ff.png
#33ffffff https://i-blog.csdnimg.cn/img_convert/d7d061e723f6f7228a725615d324b543.png
theme.colors.fontEmphasize高亮文本#ff0a59f7 https://i-blog.csdnimg.cn/img_convert/1e6e8cc88422ef9e660fbbb5fccf98bb.png
#ff317af7 https://i-blog.csdnimg.cn/img_convert/456e627c2bbe634ffd9160f538d976b9.png
theme.colors.fontOnPrimary一级文本反色#ffffffff https://i-blog.csdnimg.cn/img_convert/2cbe9b1ecb419fe82b0c28d1c96e75b0.png
#ff000000 https://i-blog.csdnimg.cn/img_convert/6e5eccb74a4ab52d6b35060c62f4f965.png
theme.colors.fontOnSecondary二级文本反色#99ffffff https://i-blog.csdnimg.cn/img_convert/2ddf0b5c8c1092cfebae221d5d4075be.png
#99000000 https://i-blog.csdnimg.cn/img_convert/7a846e37e886d7a66b1c30683e964b94.png
theme.colors.fontOnTertiary三级文本反色#66ffffff https://i-blog.csdnimg.cn/img_convert/61ecdbed867e88fccb6ab8765924b59d.png
#66000000 https://i-blog.csdnimg.cn/img_convert/c65e79216368ab6bf15a2cef2f3fad04.png
theme.colors.fontOnFourth四级文本反色#33ffffff https://i-blog.csdnimg.cn/img_convert/7a6e2722ccd49bcbead4617aec6d0de7.png
#33000000 https://i-blog.csdnimg.cn/img_convert/a20de109dff2fc11d609a2f865bf40a8.png
theme.colors.iconPrimary一级图标#e5000000 https://i-blog.csdnimg.cn/img_convert/4234a4ba4d8d45d778d658d4c0b11a5f.png
#e5ffffff https://i-blog.csdnimg.cn/img_convert/b94b848ea3911741a4616932cccaa98f.png
theme.colors.iconSecondary二级图标#99000000 https://i-blog.csdnimg.cn/img_convert/dc2d5d3c496ae16f89876b9ccba13bf2.png
#99ffffff https://i-blog.csdnimg.cn/img_convert/cf894b5a27cc83c838ce05cc71646071.png
theme.colors.iconTertiary三级图标#66000000 https://i-blog.csdnimg.cn/img_convert/8bbcbcdff38cb6780b9bc5ff655ff09c.png
#66ffffff https://i-blog.csdnimg.cn/img_convert/e7ee96721739730ba39d2e462428c38f.png
theme.colors.iconFourth四级图标#33000000 https://i-blog.csdnimg.cn/img_convert/5c9b8e05ef6b8ce50f1dfca4a5e62a5a.png
#33ffffff https://i-blog.csdnimg.cn/img_convert/99eca32288ee3d09e073d507420dcc75.png
theme.colors.iconEmphasize高亮图标#ff0a59f7 https://i-blog.csdnimg.cn/img_convert/549b893167588cf5ab0285d142625cb9.png
#ff317af7 https://i-blog.csdnimg.cn/img_convert/33597fd293cd76df36458e7e0916b396.png
theme.colors.iconSubEmphasize高亮辅助图标#660a59f7 https://i-blog.csdnimg.cn/img_convert/aee7a8c082b53ffe477de62f9a937a1e.png
#66317af7 https://i-blog.csdnimg.cn/img_convert/959c69c749c38dc5a59ec1d53eb55ca8.png
theme.colors.iconOnPrimary一级图标反色#ffffffff https://i-blog.csdnimg.cn/img_convert/0f9701361208e01cae41ae414010e798.png
#ff000000 https://i-blog.csdnimg.cn/img_convert/fdfd7aa16271c7a0ee8e814e49c0810c.png
theme.colors.iconOnSecondary二级图标反色#99ffffff https://i-blog.csdnimg.cn/img_convert/9585f3ad85332042bad6eb350509c0ee.png
#99000000 https://i-blog.csdnimg.cn/img_convert/ceaf0f507dab4a56d3f2420ca9f021c2.png
theme.colors.iconOnTertiary三级图标反色#66ffffff https://i-blog.csdnimg.cn/img_convert/ab53b3b3db8d76c985c02e37ca1960ed.png
#66000000 https://i-blog.csdnimg.cn/img_convert/f143f376b6c1d3187ea81ed04e620205.png
theme.colors.iconOnFourth四级图标反色#33ffffff https://i-blog.csdnimg.cn/img_convert/b551ece1e4b968bccf348c82367a68da.png
#33000000 https://i-blog.csdnimg.cn/img_convert/011d87491d7fc4be04b714853dbd9c64.png
theme.colors.backgroundPrimary一级配景(实色/不透明色)#ffffffff https://i-blog.csdnimg.cn/img_convert/976d196e029f7d3f9b03254f9ece0b2c.png
#ffe5e5e5 https://i-blog.csdnimg.cn/img_convert/5261bca4a97fd85d7d9e1b617a665fd5.png
theme.colors.backgroundSecondary二级配景(实色/不透明色)#fff1f3f5 https://i-blog.csdnimg.cn/img_convert/48b0625392023b4517acb917e9e3c746.png
#ff191a1c https://i-blog.csdnimg.cn/img_convert/6f7039183065d67e2654a7f060683ff5.png
theme.colors.backgroundTertiary三级配景(实色/不透明色)#ffe5e5ea https://i-blog.csdnimg.cn/img_convert/0c666849a30b98520bd6bf9286f36d83.png
#ff202224 https://i-blog.csdnimg.cn/img_convert/431867b09020bf93aeb39f312b794905.png
theme.colors.backgroundFourth四级配景(实色/不透明色)#ffd1d1d6 https://i-blog.csdnimg.cn/img_convert/4154ff856e6c1e72b76f55f3fe45040e.png
#ff2e3033 https://i-blog.csdnimg.cn/img_convert/44c3a3ed1569ca717bace9dc8e67165a.png
theme.colors.backgroundEmphasize高亮配景(实色/不透明色)#ff0a59f7 https://i-blog.csdnimg.cn/img_convert/cf432ec2fc82852723a60e21da3fbdcc.png
#ff317af7 https://i-blog.csdnimg.cn/img_convert/83e05ff3aea1ac04ba0f87982bf2bcf4.png
theme.colors.compForegroundPrimary前配景#ff000000 https://i-blog.csdnimg.cn/img_convert/c5029ccacea03c184a3dec92c4fc35be.png
#ffe5e5e5 https://i-blog.csdnimg.cn/img_convert/eca9cfb16af3f2ad3708c853c6ee96dc.png
theme.colors.compBackgroundPrimary白色配景#ffffffff https://i-blog.csdnimg.cn/img_convert/25d9adc0f9f2d9b42d8e3228eb4c7355.png
#ffffffff https://i-blog.csdnimg.cn/img_convert/75577516914fe249e11a125549073847.png
theme.colors.compBackgroundPrimaryTran白色透明配景#ffffffff https://i-blog.csdnimg.cn/img_convert/b081409c711c76e037cd3842a8723192.png
#33ffffff https://i-blog.csdnimg.cn/img_convert/1ed15e53da37602cfe0a33542536ef49.png
theme.colors.compBackgroundPrimaryContrary常亮配景#ffffffff https://i-blog.csdnimg.cn/img_convert/3b95fc1af4aa99e47b15792f0d700669.png
#ffe5e5e5 https://i-blog.csdnimg.cn/img_convert/eca9cfb16af3f2ad3708c853c6ee96dc.png
theme.colors.compBackgroundGray灰色配景#fff1f3f5 https://i-blog.csdnimg.cn/img_convert/adf14a97dda52e40302dc6cc674b5b03.png
#ffe5e5ea https://i-blog.csdnimg.cn/img_convert/0c666849a30b98520bd6bf9286f36d83.png
theme.colors.compBackgroundSecondary二级配景#19000000 https://i-blog.csdnimg.cn/img_convert/b6a5e000a4b196b9710b47323a4e50c9.png
#19ffffff https://i-blog.csdnimg.cn/img_convert/34153ed69ba23b4aaf2601e899b0128e.png
theme.colors.compBackgroundTertiary三级配景#0c000000 https://i-blog.csdnimg.cn/img_convert/c7de555244cbafe3adc69eab8c75b4c8.png
#0cffffff https://i-blog.csdnimg.cn/img_convert/321a45aa1758f3f485a1a3d4962412af.png
theme.colors.compBackgroundEmphasize高亮配景#ff0a59f7 https://i-blog.csdnimg.cn/img_convert/ac6d5e69790481c7fdccc35abbf20b9e.png
#ff317af7 https://i-blog.csdnimg.cn/img_convert/b0507149bbedc92881c207cc12714fe3.png
theme.colors.compBackgroundNeutral黑色中性高亮配景#ff000000 https://i-blog.csdnimg.cn/img_convert/75d63f7e452c25e82932fd408cfdea60.png
#ffffffff https://i-blog.csdnimg.cn/img_convert/4b11400869e46a880d39c87d35ecd2d7.png
theme.colors.compEmphasizeSecondary20%高亮配景#330a59f7 https://i-blog.csdnimg.cn/img_convert/9e082c599811b2989aa0e4104136144d.png
#33317af7 https://i-blog.csdnimg.cn/img_convert/11e9d7bfd4697fb480a3226e8517884d.png
theme.colors.compEmphasizeTertiary10%高亮配景#190a59f7 https://i-blog.csdnimg.cn/img_convert/d07f87fc8ecf1d28024a7a6103812d04.png
#19317af7 https://i-blog.csdnimg.cn/img_convert/0cb0dd2e8a6d0034c9c0c43648fc0fff.png
theme.colors.compDivider分割线颜色#33000000 https://i-blog.csdnimg.cn/img_convert/2ffa5681a65f1f916a28295c375e4eec.png
#33ffffff https://i-blog.csdnimg.cn/img_convert/1ed15e53da37602cfe0a33542536ef49.png
theme.colors.compCommonContrary通用反色#ffffffff https://i-blog.csdnimg.cn/img_convert/4b11400869e46a880d39c87d35ecd2d7.png
#ff000000 https://i-blog.csdnimg.cn/img_convert/8e6849f482b6d46d78e6d2583f2dd82e.png
theme.colors.compBackgroundFocus获焦态配景致#fff1f3f5 https://i-blog.csdnimg.cn/img_convert/adf14a97dda52e40302dc6cc674b5b03.png
#ff000000 https://i-blog.csdnimg.cn/img_convert/adf14a97dda52e40302dc6cc674b5b03.png
theme.colors.compFocusedPrimary获焦态一级反色#e5000000 https://i-blog.csdnimg.cn/img_convert/4f32790a67e0bca5dd411cf11db991e6.png
#e5ffffff https://i-blog.csdnimg.cn/img_convert/7055b68e90f86c531f60ed11488ca395.png
theme.colors.compFocusedSecondary获焦态二级反色#99000000 https://i-blog.csdnimg.cn/img_convert/b78422ccf4bebd24f7ae6fffc449db9a.png
#99ffffff https://i-blog.csdnimg.cn/img_convert/9369d53acbf3f42df4fd9b82e8dfdc6c.png
theme.colors.compFocusedTertiary获焦态三级反色#66000000 https://i-blog.csdnimg.cn/img_convert/30385f6e399e0fab57cb82ce4babc9de.png
#66ffffff https://i-blog.csdnimg.cn/img_convert/d0b1ab94fa94d0746bc4eb6df9955e43.png
theme.colors.interactiveHover通用悬停交互式颜色#0c000000 https://i-blog.csdnimg.cn/img_convert/66ff49de2806ba2ce2c43e9e228b6235.png
#0cffffff https://i-blog.csdnimg.cn/img_convert/321a45aa1758f3f485a1a3d4962412af.png
theme.colors.interactivePressed通用按压交互式颜色#19000000 https://i-blog.csdnimg.cn/img_convert/7604f611b4dc22870d35e8fa7d8332fd.png
#19ffffff https://i-blog.csdnimg.cn/img_convert/0120b2df6793cfc5691b1ca7954fd0fd.png
theme.colors.interactiveFocus通用获焦交互式颜色#ff0a59f7 https://i-blog.csdnimg.cn/img_convert/599e7e8cea5ca65e395cf036d1f349d0.png
#ff317af7 https://i-blog.csdnimg.cn/img_convert/ba9fc8c5f0c22f3238065fdfcc032672.png
theme.colors.interactiveActive通用激活交互式颜色#ff0a59f7 https://i-blog.csdnimg.cn/img_convert/599e7e8cea5ca65e395cf036d1f349d0.png
#ff317af7 https://i-blog.csdnimg.cn/img_convert/ba9fc8c5f0c22f3238065fdfcc032672.png
theme.colors.interactiveSelect通用选择交互式颜色#33000000 https://i-blog.csdnimg.cn/img_convert/19f16aecae876bf64029c38590aecef2.png
#33ffffff https://i-blog.csdnimg.cn/img_convert/1ed15e53da37602cfe0a33542536ef49.png
theme.colors.interactiveClick通用点击交互式颜色#19000000 https://i-blog.csdnimg.cn/img_convert/7604f611b4dc22870d35e8fa7d8332fd.png
#19ffffff https://i-blog.csdnimg.cn/img_convert/0120b2df6793cfc5691b1ca7954fd0fd.png

我们可以在默认值的基础上对指定的颜色值做复写,别的部分将会使用默认值。假设我们需要修改几个颜色:brand、fontPrimary、iconOnPrimary、iconFourth,修改方法示意如下:
// AppTheme.etsimport { CustomColors, CustomTheme } from '@kit.ArkUI'export class AppColors implements CustomColors {//自定义主题色  brand = 0xFF75D9;fontPrimary = 0xFFD53032iconOnPrimary = 0xFFD53032iconFourth = 0xFFD53032}export class AppTheme implements CustomTheme {public colors: AppColors = new AppColors()}export let gAppTheme: CustomTheme = new AppTheme()
2.1、设置自定义全局主题

我们可以在UIAbility中设置ThemeControl,在onWindowStageCreate()方法中setDefaultTheme,设置应用内组件的自定义主题色。
代码如下(26行):​​
// EntryAbility.etsimport {AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';import { hilog } from '@kit.PerformanceAnalysisKit';import { window, CustomColors, ThemeControl } from '@kit.ArkUI';import { gAppTheme } from './AppTheme'export default class EntryAbility extends UIAbility {onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');}onDestroy() {    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');}onWindowStageCreate(windowStage: window.WindowStage) {    // Main window is created, set main page for this ability    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');      windowStage.loadContent('pages/Index', (err, data) => {      if (err.code) {      hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');      return;      }      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');      // 在onWindowStageCreate()方法中setDefaultTheme      ThemeControl.setDefaultTheme(gAppTheme)      hilog.info(0x0000, 'testTag', '%{public}s', 'ThemeControl.setDefaultTheme done');    });}}
设置好后,我们写一个Page,代码如下:​​​​​​​
@Entry@Componentstruct DisplayPage {build() {    Column() {      List({ space: 10 }) {      ListItem() {          Column({ space: '5vp' }) {            Text('Color mode')            .margin({ top: '5vp', left: '14fp' })            .width('100%')            Row() {            Column() {                Text('Light')                  .fontSize('16fp')                  .textAlign(TextAlign.Start)                  .alignSelf(ItemAlign.Center)                Radio({ group: 'light or dark', value: 'light' })                  .checked(true)            }            .width('50%')            Column() {                Text('Dark')                  .fontSize('16fp')                  .textAlign(TextAlign.Start)                  .alignSelf(ItemAlign.Center)                Radio({ group: 'light or dark', value: 'dark' })            }            .width('50%')            }          }          .width('100%')          .height('90vp')          .borderRadius('10vp')      }      ListItem() {          Column() {            Text('Brightness')            .width('100%')            .margin({ top: '5vp', left: '14fp' })            Slider({ value: 40, max: 100 })          }          .width('100%')          .height('70vp')          .borderRadius('10vp')      }      ListItem() {          Column() {            Row() {            Column({ space: '5vp' }) {                Text('Touch sensitivity')                  .fontSize('16fp')                  .textAlign(TextAlign.Start)                  .width('100%')                Text('Increase the touch sensitivity of your screen' +                  ' for use with screen protectors')                  .fontSize('12fp')                  .fontColor(Color.Blue)                  .textAlign(TextAlign.Start)                  .width('100%')            }            .alignSelf(ItemAlign.Center)            .margin({ left: '14fp' })            .width('75%')            Toggle({ type: ToggleType.Switch, isOn: true })                .margin({ right: '14fp' })                .alignSelf(ItemAlign.Center)            }            .width('100%')            .height('80vp')          }          .width('100%')          .borderRadius('10vp')      }      }    }    .padding('10vp')    .backgroundColor('#dcdcdc')    .width('100%')    .height('100%')}} 效果如下(留意,在预览器里面看到的效果是默认主题效果,需要真机或模拟器才可以看到真实效果):

https://i-blog.csdnimg.cn/img_convert/d1082da43bb264c6cc54ba6dcf35356b.jpeg
默认情况下,效果如下:

https://i-blog.csdnimg.cn/img_convert/a23ccf14f68795bcf47e5910fe1e0241.png

2.3、Page中获取自定义主题

我们可以在onWillApplyTheme回调函数获取用于使自定义组件获取当前收效的Theme对象。我们可以获取自定义的主题对象,读取指定的主题色值,代码示例如下(9 ~ 10行):​​​​​​
  import { Theme, ThemeControl } from '@kit.ArkUI'@Entry@Componentstruct DisplayPage {    @State menuItemColor: ResourceColor = $r('sys.color.background_primary')      onWillApplyTheme(theme: Theme) {    // theme是当前生效的主题对象      this.menuItemColor = theme.colors.backgroundPrimary;    }      build() {    // ...    }}
2.4、局部应用主题色

我们可以通过设置WithTheme,将自定义主题Theme的配色应用于内部组件的默认样式。在WithTheme的作用范围内,组件的配色会根据Theme的配色举行调解。代码如下(29行):​​​​​​​
import { CustomColors, CustomTheme, Theme } from '@kit.ArkUI'class AppColors implements CustomColors {fontPrimary: Color = Color.Pink;backgroundEmphasize: Color = Color.Pink;}class AppColorsSec implements CustomColors {fontPrimary: Color = Color.Orange;backgroundEmphasize: Color = Color.Orange;}class AppTheme implements CustomTheme {public colors: AppColors = new AppColors()}class AppThemeSec implements CustomTheme {public colors: AppColors = new AppColorsSec()}@Entry@Componentstruct DisplayPage {@State customTheme: CustomTheme = new AppTheme()@State message: string = '切换自定义主题风格'count = 0;build() {    WithTheme({ theme: this.customTheme }) {      Row(){      Column() {          Text('WithTheme')            .fontSize(30)            .margin({bottom: 10})          Text(this.message)            .margin({bottom: 10})          Button('切换主题').onClick(() => {            this.count++;            if (this.count > 1) {            this.count = 0;            }            switch (this.count) {            case 0:                this.customTheme = new AppTheme();                break;            case 1:                this.customTheme = new AppThemeSec();                break;            }          })      }      .width('100%')      }      .height('100%')      .width('100%')    }}} 如示例代码所示,使用WithTheme({ theme: this.myTheme })可将作用域内组件的配色设置为自定义主题风格。后续可以通过更新this.myTheme来更换主题风格。onWillApplyTheme回调函数用于使自定义组件能够获取当前收效的Theme对象。效果如下:

https://i-blog.csdnimg.cn/img_convert/03043cf3b2eda777880bc2c78a8f69e6.gif

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 鸿蒙UI开辟——自定义主题色