【从零开始鸿蒙开发: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管理页面路由
相关推荐
এ慕ོ冬℘゜几秒前
jQuery 核心方法
前端·javascript·jquery
阳火锅1 分钟前
老板要周报?我说不用,代码提交就是进度
前端·javascript·vue.js
chjif1 分钟前
一张照片和一段声音如何生成口播视频:MiniMax H3 音画同步实测
java·前端·javascript
lucky九年3 分钟前
deepseek harness主题插件dsh-web-theme
前端
2601_962203519 分钟前
【SpringBoot3】面向切面 AspectJ AOP 使用详解
开发语言·前端·python
贾伟康14 分钟前
【天体运行模拟|08】HarmonyOS ArkTS 单位换算实战:处理天文尺度、科学计数与精度
harmonyos·arkts·arkui·数值精度·单位换算
XLYcmy37 分钟前
HTML/CSS/JS 基础与 Vue 技术栈深度解析
java·前端·css·html·vue3·vue2·api
新知图书1 小时前
12.3 智能体中Skill的约束与自进化实战
java·前端·数据库
2501_919749031 小时前
华为鸿蒙免费反诈APP—小羊反诈
华为·harmonyos·鸿蒙
风月说与山鬼1 小时前
四、Tailwind CSS——间距与尺寸
前端·css·tailwind css