文档开发者中心
我的
|

ArkUI (方舟UI框架)

HarmonyOS 5

启动的闪屏页怎么配置

已解决
HarmonyOS Next上有splashView的概念吗,就是启动的时候,有一个启动页。 HarmonyOS Next上我看只有一个启动图,我可以设置这个图的时间长一点吗?现在这个图的时间比较短,我们首页是H5的,会导致用户看到的是骨架图,我们想延长一点。不让用户看到骨架图。
点赞
收藏
回复
2
分享
举报
浏览351 编辑于2025-10-31 08:39广东
全部评论
最多点赞
最新发布
最早发布
|
采纳答复
可以使用创建子窗口的方式实现您的需求,可参考以下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');

  }

}

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

```

展开全部
1
1楼回复于2024-11-07 09:27 来自广东
  • 一骑绝尘
    使用上述方式报创建创建子窗口失败,还需要设置什么?
    2025-07-24 08:05 来自四川
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要提问题

了解社区公约,与您携手共创和谐专业的开发者社区。