chendeben 1 год назад
Родитель
Сommit
39489e17c2

+ 3 - 0
entry/src/main/ets/MyAbilityStage.ets

@@ -1,10 +1,13 @@
 import AbilityStage from '@ohos.app.ability.AbilityStage';
 import hilog from '@ohos.hilog';
+import { PreferencesUtil } from '@pura/harmony-utils';
 
 export default class MyAbilityStage extends AbilityStage {
   async onCreate(): Promise<void> {
     hilog.info(0x0000, 'Heanup', '%{public}s', 'Ability onCreate');
     try {
+      let themeColor = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
+      AppStorage.setOrCreate('themeColor', themeColor);
       // 保存当前颜色模式到 AppStorage
       AppStorage.setOrCreate('currentColorMode', this.context.config.colorMode);
       hilog.info(0x0000, 'Heanup', '当前 colorMode:'+this.context.config.colorMode);

+ 3 - 2
entry/src/main/ets/pages/NewIndex.ets

@@ -111,6 +111,7 @@ struct NewIndex{
   /** 是否可以返回上一级 */
   @Provide isCanBack:boolean=  false
   @StorageProp('currentColorMode') currentMode: number = ConfigurationConstant.ColorMode.COLOR_MODE_LIGHT;
+  @StorageProp('themeColor') themeColor: string = '#FF4081';
 
   /**
    * 一多界面适配断点系统
@@ -296,14 +297,14 @@ struct NewIndex{
               SymbolGlyph((item.img as sysResource).value as Resource)
                 // .size({ width: 22, height: 22 })
                 .fontSize(22)
-                .fontColor([$r("app.color.img_color")])
+                .fontColor([this.themeColor])
                 .alignSelf(ItemAlign.Center)
                 .margin({ left: 2 })
             }else if (typeof item.img === 'object' && item.img !== null && (item.img as sysResource).type === 'ibest') {
               IBestIcon({
                 name: (item.img as sysResource).value as string,
                 iconSize:22,
-                color: $r("app.color.img_color"),
+                color: this.themeColor,
               }).margin({ left: 2 })
                 .alignSelf(ItemAlign.Center)
             }else {

+ 65 - 2
entry/src/main/ets/pages/SettingPage.ets

@@ -87,6 +87,7 @@ export struct SettingPage {
     })
     .setTitleBarNormalPadding(0)
   @State verName: string = ''
+  @StorageProp('themeColor') themeColor: string = PreferencesUtil.getStringSync('THEME_COLOR', '#FF4081');
 
   apiDialogController: CustomDialogController = new CustomDialogController({
     builder: CustomContentDialog({
@@ -214,9 +215,34 @@ export struct SettingPage {
         Line().width('100%').height('100%')
       }
       .height(this.isPhoneLan()?0:px2vp(AppUtil.getStatusBarHeight()))
-      .backgroundColor($r('app.color.title_bar_bg'))
+      .backgroundColor(this.themeColor)
       .expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
-      TitleBar({ model: $titleBarModel })
+      // 自定义标题栏
+      Stack() {
+        // 居中标题
+        Text('通用设置')
+          .fontSize(20)
+          .fontColor(Color.White)
+          .align(Alignment.Center)
+        // 左侧返回按钮
+        Row() {
+          Image($r('app.media.left_back_white'))
+            .width(32)
+            .height(32)
+            .margin({ left: 12, right: 8 })
+            .onClick(() => {
+              router.back();
+            })
+          Blank().flexGrow(1)
+          Blank().width(32)
+        }
+        .height(48)
+        .width('100%')
+        .alignItems(VerticalAlign.Center)
+      }
+      .height(48)
+      .width('100%')
+      .backgroundColor(this.themeColor)
       Scroll() {
         Column() {
           // 主题设置分组
@@ -261,6 +287,34 @@ export struct SettingPage {
             }
             .height(55)
 
+            // 主题色选择
+            Row() {
+              Text('主题色')
+                .margin({ left: 18 })
+                .fontSize(15)
+                .fontColor(Color.Gray)
+                .fontWeight(480)
+                .layoutWeight(1)
+              Row() {
+                ForEach(SettingPage.THEME_COLOR_LIST, (color: string, index: number) => {
+                  Blank()
+                    .width(32)
+                    .height(32)
+                    .backgroundColor(color)
+                    .borderRadius(16)
+                    .border({ width: this.themeColor === color ? 3 : 1, color: this.themeColor === color ? Color.Black : Color.Gray })
+                    .margin({ right: 8 })
+                    .onClick(() => {
+                      this.themeColor = color
+                      PreferencesUtil.put(SettingPage.THEME_COLOR_KEY, color)
+                      AppStorage.setOrCreate('themeColor', color)
+                    })
+                })
+              }
+              .margin({ right: 18 })
+            }
+            .height(55)
+
             Line().width('100%').height(0.3).backgroundColor($r('app.color.index_tab_unselected_font_color'))
 
             Row() {
@@ -826,4 +880,13 @@ export struct SettingPage {
     .margin({ bottom: 30 })
   }
 
+  public static THEME_COLOR_KEY: string = 'THEME_COLOR';
+  public static THEME_COLOR_LIST: Array<string> = [
+    '#FF4081', // 默认
+    '#0A59F7', // 蓝
+    '#64BB5C', // 绿
+    '#ED6F21', // 橙
+    '#5BA854'  // 青
+  ];
+
 }