当前位置: 首页 > news >正文

鸿蒙启动页开发

鸿蒙启动页开发

1.1 更改应用名称和图标

1.更改应用图标

  1. 找到moudle.json5文件,找到应用启动的EntryAbility下面的icon,将原来的图标改成自己设置的即可

image-20250224120305604

2.更改应用名称

image-20250224120614234

image-20250302234913382

3.效果展示

image-20250302235217531

2.1 广告页面开发

image-20250302182914432

3.1 详细介绍

3.1.1 启动页面

import { PrivacyDialog } from '../views/components/PrivacyDialog'
import { router, window } from '@kit.ArkUI'
import { preferences } from '@kit.ArkData'
import { common } from '@kit.AbilityKit'@Entry
@Component
struct launchPage {//获取应用的上下文context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext//获取页面的上下文// context:Context = getContext()@StateisStore: boolean = trueaboutToAppear(): void {window.getLastWindow(getContext()).then(win => {win.setWindowLayoutFullScreen(true)})const store = preferences.getPreferencesSync(this.context, {'name': 'infoStore'})this.isStore = store.getSync('isStore', true) as booleanconsole.info(`userAction: ${this.isStore}`)}async saveInfo() {const store = preferences.getPreferencesSync(this.context, {'name': 'infoStore'})store.putSync('isStore', false)store.flush()}//在页面出现之后:需要展示弹窗onPageShow(): void {//isStore用于定义是否保存的标识  如果显示true,就不用打开自定义弹窗,直接跳到广告界面// promptAction.showToast({//   message: this.isStore+''// })if (this.isStore) {this.controller.open()} else {//跳到广告界面router.pushUrl({url: 'pages/AdvertisementPage'})}}// context:Context:getContext()controller: CustomDialogController = new CustomDialogController({builder: PrivacyDialog({cancel: () => {this.context?.terminateSelf()//不同意关闭应用},confirm: () => { //当你点击同意,就会调用saveInfo方法this.saveInfo()//TODO 跳到广告页面router.pushUrl({url: 'pages/AdvertisementPage'})},}),alignment: DialogAlignment.Bottom, //基准位置// offset:{dx:30,dy:30}}//设置弹窗位置)build() {Stack() {//设置第一层Image($r('app.media.back'))Column({ space: 10 }) {Image($r('app.media.study_app')).width(80).aspectRatio(1)Text('健康学习').fontSize(20).fontWeight(FontWeight.Bold)Text('学习总有新玩法').fontWeight(FontWeight.Bold)}.width('100%').height('100%').padding({top: 100})}.height('100%').width('100%')}
}

3.1.2 自定义弹层

import { router } from '@kit.ArkUI'@Preview
@CustomDialog
export struct PrivacyDialog {controller:CustomDialogController = new CustomDialogController({builder: ''})//定义两个用来接收的方法cancel:Function = ()=>{}confirm:Function = ()=>{}build() {Column(){Text('欢迎使用我的应用')Text('我们充分尊重用户的隐私权,并按照法律要求和业界成熟的安全标准,为您的个人信息提供相应的安全保护措施。')Text('协议隐私保护声明').fontColor('#007fdd').onClick(()=>{// TODOrouter.pushUrl({url:''})})Text('(以下简称为“本声明”)以便您了解我们如何搜集、使用、披露、保护、存储、及传输您的个人数据。请您仔细阅读本声明。如您有任何疑问,请告知我们。')Row(){Text('不同意').fontColor('#007fdd').onClick(()=>{this.controller.close()   //点击不同意,关闭this.cancel()})Blank()Text('同意').fontColor('#007fdd').onClick(()=>{this.controller.close()this.confirm()})}.width('70%')}}
}

3.1.3 广告页面

import { router, window } from '@kit.ArkUI'@Entry
@Component
struct AdvertisementPage {@State time: number = 5@State timeID: number = -1aboutToAppear(): void {window.getLastWindow(getContext()).then(win => {win.setWindowLayoutFullScreen(true)})}onPageShow(): void {this.timeID = setInterval(() => {console.log('test', this.time)if (this.time > 0) {this.time--} else if (this.time == 0) {clearTimeout(this.timeID)router.pushUrl({url: 'pages/Index'})}}, 1000)}build() {Stack() {Image($r('app.media.back'))Row() {Text('跳过广告' + this.time + 's').fontSize(20).backgroundColor('rgba(0,0,0,0.1)').padding(8).borderRadius(30)}.width('100%').height('100%').justifyContent(FlexAlign.End).alignItems(VerticalAlign.Top).padding({top: 30,right: 30})Row({ space: 10 }) {Image($r('app.media.study_app')).width(80).aspectRatio(1)Column({ space: 5 }) {Text('健康学习').fontSize(30)Text('学习总有新玩法').fontSize(20)}.height(80).justifyContent(FlexAlign.Start)}.width('100%').height('100%').justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Bottom).padding({bottom: 16})}.height('100%').width('100%')}
}
http://www.lryc.cn/news/547266.html

相关文章:

  • Unity 文字高度自适应
  • Teaching Small Language Models Reasoning throughCounterfactual Distillation
  • 快速开始React开发(一)
  • 2025最新Transformer模型及深度学习前沿技术应用
  • 极狐GitLab 正式发布安全版本17.9.1、17.8.4、17.7.6
  • [环境搭建篇] Windows 环境下如何安装Docker工具
  • JavaScript 数组和字符串方法详解
  • 达梦数据库系列之Mysql项目迁移为达梦项目
  • 10个实用IntelliJ IDEA插件
  • 10分钟从零开始搭建机器人管理系统(飞算AI)
  • [自动驾驶-传感器融合] 多激光雷达的外参标定
  • 怎么让呼叫中心支持高并发
  • Elasticsearch简单学习
  • 就像BGP中的AS_PATH一样,无论路途多远,我愿意陪你一起走——基于华为ENSP的BGP的路由负载均衡及过滤深入浅出
  • valgrind 检测多线程 bug,检测 并发 bug concurrent bug parallel bug
  • 游戏引擎学习第135天
  • 异步操作返回原始上下文
  • 区块链中的数字签名:安全性与可信度的核心
  • vulnhub渗透日记23:bulldog
  • macOS - 使用 tmux
  • Armbian: 轻量级 ARM 设备专用 Linux 发行版全面解析
  • 微服务通信:用gRPC + Protobuf 构建高效API
  • Spring Boot 整合 JMS-ActiveMQ,并安装 ActiveMQ
  • 容器 /dev/shm 泄漏学习
  • Spring Boot 3.x 基于 Redis 实现邮箱验证码认证
  • 车载测试:智能座舱测试中多屏联动与语音交互的挑战
  • C/C++输入输出(1)
  • 前端面试场景题葵花宝典之四
  • 探索Elasticsearch:索引的CRUD
  • Java数据结构第十六期:走进二叉树的奇妙世界(五)