HarmonyOS 启动的闪屏页怎么配置

HarmonyOS有类似splashView的概念吗,就是启动的时候,有一个启动页。 HarmonyOS上我看只有一个启动图,我可以设置这个图的时间长一点吗?现在这个图的时间比较短,我们首页是H5的,会导致用户看到的是骨架图,我们想延长一点。不让用户看到骨架图。

HarmonyOS
2024-12-25 12:16:52
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Excelsior_abit

可以使用创建子窗口的方式实现,可参考以下demo思路:

//EntryAbility ,在EntryAbility 里加载根页面以及创建子窗口100%宽高
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { display, window } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
import { calendarManager } from '@kit.CalendarKit';
import common from '@ohos.app.ability.common';
import { JSON } from '@kit.ArkTS';

let windowStage_: window.WindowStage | null = null;
let sub_windowClass: window.Window | null = null;
export let calendarMgr: calendarManager.CalendarManager;
export let mContext: common.UIAbilityContext;

export default class EntryAbility extends UIAbility {
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {

    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
  }

  onDestroy(): void {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
  }

  showSubWindow() {
    // 1.创建应用子窗口。
    if (windowStage_ == null) {
      console.error('Failed to create the subwindow. Cause: windowStage_ is null');
    }
    else {
      windowStage_.createSubWindow("mySubWindow", (err: BusinessError, data) => {
        let errCode: number = err.code;
        if (errCode) {
          console.error('Failed to create the subwindow. Cause: ' + JSON.stringify(err));
          return;
        }
        sub_windowClass = data;
        console.info('Succeeded in creating the subwindow. Data: ' + JSON.stringify(data));
        // 2.子窗口创建成功后,设置子窗口的位置、大小及相关属性等。
        // sub_windowClass.moveWindowTo(300, 300, (err: BusinessError) => {
        //   let errCode: number = err.code;
        //   if (errCode) {
        //     console.error('Failed to move the window. Cause:' + JSON.stringify(err));
        //     return;
        //   }
        //   console.info('Succeeded in moving the window.');
        // });
        let displayClass: display.Display = display.getDefaultDisplaySync();//获取屏幕大小
        sub_windowClass.resize(displayClass.width, displayClass.height, (err: BusinessError) => {
          let errCode: number = err.code;
          if (errCode) {
            console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
            return;
          }
          console.info('Succeeded in changing the window size.');
        });
        // 3.为子窗口加载对应的目标页面。
        sub_windowClass.setUIContent("components/media/Video", (err: BusinessError) => {
          let errCode: number = err.code;
          if (errCode) {
            console.error('Failed to load the content. Cause:' + JSON.stringify(err));
            return;
          }
          console.info('Succeeded in loading the content.');
          // 3.显示子窗口。
          (sub_windowClass as window.Window).showWindow((err: BusinessError) => {
            let errCode: number = err.code;
            if (errCode) {
              console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
              return;
            }
            console.info('Succeeded in showing the window.');
          });
        });
      })
    }
  }

  destroySubWindow() {
    // 4.销毁子窗口。当不再需要子窗口时,可根据具体实现逻辑,使用destroy对其进行销毁。
    (sub_windowClass as window.Window).destroyWindow((err: BusinessError) => {
      let errCode: number = err.code;
      if (errCode) {
        console.error('Failed to destroy the window. Cause: ' + JSON.stringify(err));
        return;
      }
      console.info('Succeeded in destroying the window.');
    });
  }

  onWindowStageCreate(windowStage: window.WindowStage): void {
    // 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;
      }
      AppStorage.setOrCreate('windowStage',windowStage)
      windowStage_ = windowStage
      this.showSubWindow();
    });
  }

  onWindowStageDestroy(): void {
    // Main window is destroyed, release UI related resources
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
  }

  onForeground(): void {
    // Ability has brought to foreground
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
  }

  onBackground(): void {
    // Ability has back to background
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
  }
}
  • 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.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.

在子窗口文件中使用计时函数,到时间后使用window.findWindow(“mySubWindow”).destroyWindow()销毁子窗口显示首页

分享
微博
QQ
微信
回复
2024-12-25 14:24:57


相关问题
鸿蒙实现怎么实现?
5844浏览 • 1回复 待解决
HarmonyOS 如何自定义App冷启动
2076浏览 • 1回复 待解决
HarmonyOS 哪里配置页面
798浏览 • 1回复 待解决
HarmonyOS启动启动实现
1000浏览 • 1回复 待解决
HarmonyOS video设置加载图
887浏览 • 1回复 待解决
HarmonyOS 启动设置问题
1428浏览 • 1回复 待解决
HarmonyOS 启动广告跳转问题
842浏览 • 1回复 待解决
HarmonyOS如何设置应用启动
1718浏览 • 1回复 待解决
HarmonyOS 怎样自定义应用启动
1206浏览 • 1回复 待解决
HarmonyOS 启动背景图适配
935浏览 • 1回复 待解决
HarmonyOS 应用横竖是如何配置
460浏览 • 1回复 待解决
如何启动应用系统设置详情
2675浏览 • 1回复 待解决