【从零开始鸿蒙开发:01】自定义闪屏页

文章目录

大体介绍

文件介绍

其中:

  • pages为我们的页面内容(我个人理解功能性小于activity但是大于fragment)
  • route_map.json 为自定义的路由表(使用Navigation 而不是Router
  • SplashPage.ets 为我们自定义的闪屏文件
  • HomePage.ets 为我们测试的二级页面
  • route_map.json 需要配置在module.json5中

各部分代码

SplashPage.ets

bash 复制代码
import { router } from "@kit.ArkUI"

@Entry
@Component
struct SplashPage {
  build() {
    Column() {
      Image($r("app.media.huawei_logo"))
        .padding({
          left: "15%",
          right: "15%"
        }).width("100%")

      LoadingProgress()
        .width("20%")
        .height("20%")
        .color(Color.Red)
    }.height('100%')
    .width('100%')
    .alignItems(HorizontalAlign.Center)
    .justifyContent(FlexAlign.Center)
  }

  aboutToAppear(): void {
    setTimeout(() => {
      router.pushUrl(
        { url: "pages/Index" }
      ).then(()=>{
        router.clear()
      })
    }, 2000)
  }
}

Index.ets

bash 复制代码
@Entry
@Component
struct Index {
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack();



  build() {
    Navigation(this.pageInfos) {
        Column(){
          Button("TO HOME").onClick(()=>{
            this.pageInfos.pushPathByName("HomePage",null,true)
          })
        }
    }
    .height('100%')
    .width('100%')
    .mode(NavigationMode.Stack)
    .hideBackButton(true)
    .titleMode(NavigationTitleMode.Mini)
    .toolbarConfiguration([

    ])
  }
}

HomePage.ets

bash 复制代码
@Builder
export function PageOnBuilder(){
  HomePage()
}

@Component
struct HomePage {
  @State message: string = 'this is home';

  build() {
    NavDestination(){
      RelativeContainer() {
        Text(this.message)
          .id('HomePageHelloWorld')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .alignRules({
            center: { anchor: '__container__', align: VerticalAlign.Center },
            middle: { anchor: '__container__', align: HorizontalAlign.Center }
          })
      }
      .height('100%')
      .width('100%')
    }
  }
}

route_map.json

bash 复制代码
{
  "routerMap": [
    {
      "name": "HomePage",
      "pageSourceFile": "src/main/ets/pages/HomePage.ets",
      "buildFunction": "PageOnBuilder"
    }
  ]
}

module.json5

bash 复制代码
 {
  "module": {
  	...
    "routerMap": "$profile:route_map",
    ...
    ]
  }
}

流程

  1. 修改启动页为自定义的Splash
  2. 自定义操作后跳到真正的Index页面
  3. Index页面用Navigation管理页面路由
相关推荐
前端小巷子11 分钟前
JS 打造丝滑手风琴
前端·javascript·面试
Mintopia24 分钟前
多模态 AIGC 在 Web 内容创作中的技术融合实践:把“创作引擎”装进浏览器
前端·javascript·aigc
鹏多多.27 分钟前
flutter-使用fluttertoast制作丰富的高颜值toast
android·前端·flutter·ios
Mintopia37 分钟前
Next.js 的 Web Vitals 监测与 Lighthouse 分析:从底层到实战的快乐科学
前端·javascript·next.js
HarmonyOS小助手40 分钟前
HEIF:更高质量、更小体积,开启 HarmonyOS 图像新体验
harmonyos·鸿蒙·鸿蒙生态
charlie11451419144 分钟前
前端三件套简单学习:HTML篇1
开发语言·前端·学习·html
很多石头1 小时前
前端img与background-image渲染图片对H5页面性能的影响
前端·css
yenggd1 小时前
3种XSS攻击简单案例
前端·xss
盖头盖1 小时前
【xss基本介绍】
前端·xss
一枚前端小能手1 小时前
「周更第2期」实用JS库推荐:Rsbuild
前端·javascript