HarmonyOS鸿蒙Next中启动页背景和startWindowIcon属性设置为同一张图时,如何解决出现的闪屏问题

HarmonyOS鸿蒙Next中启动页背景和startWindowIcon属性设置为同一张图时,如何解决出现的闪屏问题

【问题现象】

当启动页背景和module.json中startWindowIcon属性设置为同一张图,当APP启动时,相当于加载了两张图,不能平滑过渡,会有闪屏现象。

【背景知识】

Image为图片组件,常用于在应用中显示图片,支持png、jpg、jpeg、bmp、svg、webp、gif和heif类型的图片格式。

【参考材料】

Image组件

【解决方案】

使用Image组件代替Column组件背景的方案,并设置图片加载方式为同步。

参考示例代码如下:

@Entry
@Component
struct WhitePage {
  aboutToAppear(): void {
    setTimeout(() => {
    }, 10 * 1000)
  }

  build() {
    Column() {
      Image($r('app.media.splash_bg'))
        .width('100%')
        .height('100%')
        .syncLoad(true) // 设置图片为同步加载
    }
    .width('100%')
    .height('100%')
  }
}

更多关于HarmonyOS鸿蒙Next中启动页背景和startWindowIcon属性设置为同一张图时,如何解决出现的闪屏问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于HarmonyOS鸿蒙Next中启动页背景和startWindowIcon属性设置为同一张图时,如何解决出现的闪屏问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


使用Image组件代替Column组件背景,并设置图片加载方式为同步

示例代码如下:

@Entry
@Component
struct WhitePage {
  aboutToAppear(): void {
    setTimeout(() => {
    }, 10 * 1000)
  }

  build() {
    Column() {
      Image($r('app.media.splash_bg'))
        .width('100%')
        .height('100%')
        .syncLoad(true) // 设置图片为同步加载
    }
    .width('100%')
    .height('100%')
  }
}
回到顶部