码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • HarmonyOS开发实战(黑马健康系列一:欢迎页)


    系列文章目录

    (零)鸿蒙HarmonyOS入门:如何配置环境,输出“Hello World“
    (一)鸿蒙HarmonyOS开发基础
    (二)鸿蒙HarmonyOS主力开发语言ArkTS-基本语法
    (三)鸿蒙HarmonyOS主力开发语言ArkTS-状态管理
    (四)鸿蒙HarmonyOS主力开发语言ArkTS-渲染控制
    (五)鸿蒙HarmonyOS主力开发语言ArkTS-数据懒加载(LazyForEach)


    文章目录

    • 系列文章目录
    • 前言
    • 一、核心代码
      • 1.WelcomePage.ets
      • 2.UserPrivacyDialog.ets
      • 3.页面效果
    • 总结
    • 扩展


    前言

    提示::

    案例来源于b站的黑马课程


    提示:以下是本篇文章正文内容,下面案例可供参考

    一、核心代码

    1.WelcomePage.ets

    import UserPrivacyDialog from '../view/welcome/UserPrivacyDialog'
    import common from '@ohos.app.ability.common'
    import PreferencesUtil from '../common/utils/PreferencesUtil'
    import router from '@ohos.router'
    @Extend(Text) function opacityWhiteText(opacity: number, fontSize: number = 10) {
      .fontSize(fontSize)
      .opacity(opacity)
      .fontColor(Color.White)
    }
    
    const USER_PRIVACY_KEY: string = 'userPrivacyKey'
    
    @Entry
    @Component
    struct WelcomePage {
      // 获取上下文,用户退出APP
      context = getContext(this) as common.UIAbilityContext
    
      // 定义用户协议弹窗
      controller: CustomDialogController = new CustomDialogController({
        builder: UserPrivacyDialog({
          confirm: () => this.onConfirm(),
          cancel: () => this.exitApp()
        })
      })
    
      // 用户协议同意处理逻辑
       async onConfirm() {
        //   保存用户同意信息到首选项
        await PreferencesUtil.putPreferenceValue(USER_PRIVACY_KEY, true)
        //   跳转到首页
        this.jumpToIndex()
      }
      // 用户协议不同退出APP
      exitApp() {
        this.context.terminateSelf()
      }
    
    
      async aboutToAppear() {
        //读取用户首选项
        let isAgree = await PreferencesUtil.getPreferenceValue(USER_PRIVACY_KEY, false)
        // 同意则跳转首页
        if (isAgree) {
          this.jumpToIndex()
        } else {
          console.log('2222')
          // 不同意则继续打开用户协议
          this.controller.open()
        }
      }
      // 跳转到首页
      jumpToIndex() {
        setTimeout(() => {
          router.replaceUrl({
            url: 'pages/Index'
          })
        }, 1000)
      }
      build() {
        Column({ space: 10 }) {
          //中央
          Row() {
            Image($r('app.media.home_slogan'))
              .width(260)
          }.layoutWeight(1)
    
    
          Image($r('app.media.home_logo'))
            .width(150)
          Row() {
            // Text('技术支持').fontSize(12).opacity(0.8).fontColor(Color.White)
            Text('技术支持').opacityWhiteText(0.8,12)
            Text('IPV6')
              .fontSize(10)
              .opacity(0.8)
              .fontColor(Color.White)
              .border({ style: BorderStyle.Solid, width: 1, color: Color.White, radius: 15 })
              .padding({ left: 5, right: 5 })
            Text('网络').fontSize(12).opacity(0.8).fontColor(Color.White)
    
    
          }
    
          Text(`'减更多'指黑马健康APP希望通过软件工具的形式,帮助更多用户实现身材管理`)
            .fontSize(10)
            .opacity(0.6)
            .fontColor(Color.White)
          Text('蜀ICP备11013304号-1')
            .fontSize(10)
            .opacity(0.6)
            .fontColor(Color.White)
            .margin({ bottom: 35 })
        }
        .width('100%')
        .height('100%')
        .backgroundColor($r('app.color.welcome_page_background'))
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99

    2.UserPrivacyDialog.ets

    import { CommonConstants } from '../../common/constants/CommonConstants'
    // @Preview
    @CustomDialog
    export  default  struct UserPrivacyDialog {
      controller :CustomDialogController
    
      // 定义空同意与不同方法,由调用方具体实现
      confirm: () => void
      cancel: () => void
    
    
      build() {
        Column({space:CommonConstants.SPACE_4}){
          Text($r('app.string.user_privacy_title'))
            .fontSize(20)
            .fontWeight(CommonConstants.FONT_WEIGHT_700)
    
          Text($r('app.string.user_privacy_content'))
    
          Button($r('app.string.agree_label'))
            .width(150)
            .backgroundColor($r('app.color.primary_color'))
            .onClick(() => {
              this.confirm()
              this.controller.close()
            })
    
          Button($r('app.string.refuse_label'))
            .width(150)
            .backgroundColor($r('app.color.lightest_primary_color'))
            .fontColor($r('app.color.light_gray'))
            .onClick(() => {
              this.cancel()
              this.controller.close()
            })
        }
      }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    3.页面效果

    在这里插入图片描述


    总结

    主要涉及到线性布局(Row/Column)、文本显示(Text/Span)、按钮(Button)等。

    扩展

    Column接口文档

  • 相关阅读:
    DS18B20 数字温度传感器实验
    ansible控制windows机器
    【JavaEE】文件操作
    Gumroad如何使用美国虚拟visa卡购买图集教程?gumroad国内银行卡能付款吗?gumroad付款教程?
    Javascript笔记 rest VS spread
    【App自动化测试】(八)三种等待方式——强制等待、隐式等待、显示等待
    一行代码禁止用户调试前端代码
    Leetcode刷题详解——使用最小花费爬楼梯
    网安强校广州大学,学硕改考408!计院专硕也变难了!
    Kubernetes技术与架构-Ingress
  • 原文地址:https://blog.csdn.net/qq_44160056/article/details/138201506
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号