【鸿蒙实战开发】手写鸿蒙应用-键盘音乐

先看结果

image.png

关键技术

  1. 基本布局技巧
  2. AVPlayer
  3. 面向对象
  4. 全部采用 V2版本 状态管理技术

新建一个项目

  1. 创建项目

image.png

  1. 新建项目

image.png

  1. 目录结构 - 可以后期用到再去新建

image.png

设置全局沉浸式

设置和不设置全局沉浸式的区别是这样的

image.png

  1. src/main/ets/entryability/EntryAbility.ets 文件内进行编辑

  2. loadContent 中进行设置

image.png

 `//   1 设置应用全屏
 let windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口

 // 2   设置沉浸式
 windowClass.setWindowLayoutFullScreen(true)` </pre>
  1. 此时效果是这样的 , 文字也会直接在状态栏上显示

image.png

  1. 此时,考虑到不同设备的状态栏高度可能不同,所以我们需要

    1. 动态获取状态栏高度,存到全局状态中 AppStorageV2
    2. 页面读取全局状态中的状态栏高度,单独给页面进行设置
    
      `//   1 获取应用窗口对象
      const windowClass: window.Window = windowStage.getMainWindowSync(); // 获取应用主窗口
      //  2  设置全屏
      windowClass.setWindowLayoutFullScreen(true)
      // 3 获取布局避让遮挡的区域
      const type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR;
    
      const avoidArea = windowClass.getWindowAvoidArea(type);
      const bottomRectHeight = avoidArea.bottomRect.height; // 获取到导航条区域的高度
      const vpHeight = px2vp(bottomRectHeight) //  转换成 vp单位的数值
      //   4 把导航栏高度数据 存在全局
      const appStatu = AppStorageV2.connect(AppStatu, "AppStatu", () => new AppStatu())
      appStatu!.vpHeight = vpHeight` </pre>
    
  2. AppStatu 是自定义类,用来存储数据 状态栏高度数据的

    src/main/ets/types/index.ets


       `@ObservedV2
       export class AppStatu {
        @Trace vpHeight: number =0
       }` </pre>

搭建背景

image.png

 `build() {

 Column({ space: 30 }) {

 }
 .width("100%")
 .height("100%")
 .backgroundImage($r("app.media.startIcon"))
 .backgroundImageSize(ImageSize.FILL)
 .backdropBlur(1000) // 对背景进行模糊

 }` </pre>

搭建琴谱

image.png

琴谱背景区域

使用背景图片+模糊搭建琴谱区域,高度由内容撑开

image.png


 `@Builder
 MusicScore() {
 // 琴谱
 Column({ space: 3 }) {
 Text("琴谱")
 }
 .width("100%")
 .backgroundImage($r("app.media.startIcon"))
 .backgroundImageSize(ImageSize.FILL)
 .backdropBlur(500) // 对背景进行模糊
 .padding({
 top: this.appStatu!.vpHeight + 20
 })
 }

 build() {

 Column({ space: 30 }) {
 //   1 琴谱
 this.MusicScore()
 }
 .width("100%")
 .height("100%")

 .backgroundImage($r("app.media.startIcon"))
 .backgroundImageSize(ImageSize.FILL)
 .backdropBlur(1000) // 对背景进行模糊

 }` </pre>

定义琴谱数据类型

琴谱只需要两个字段

  1. 琴谱对应歌曲的标题 t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值