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

鸿蒙 OS 开发零基础快速入门教程

视频课程:
在这里插入图片描述

东西比较多, 这里主要分享一些代码和案例.

开关灯效果案例: 开灯
在这里插入图片描述

开关灯效果案例: 关灯
在这里插入图片描述

Column 和 Row 的基本用法

@Entry
@Component
struct Index {@State message: string = '张三';build() {// 一行内容Row() {// 一列内容Column() {// 文本内容Text(this.message).fontSize(50)// 字体大小.fontWeight(FontWeight.Bold) // 字体粗细}.width("100%")}.height('100%')}
}

一行两列的布局

@Entry
@Component
struct Index {@State message: string = '张三';build() {// 一行内容Row() {// 一列内容Column() {// 文本内容Text(this.message).fontSize(50)// 字体大小.fontWeight(FontWeight.Bold) // 字体粗细}.width("50%")// 一列内容Column() {// 文本内容Text(this.message).fontSize(50)// 字体大小.fontWeight(FontWeight.Bold) // 字体粗细}.width("50%")}.height('100%')}
}

开关灯效果案例的基本实现

@Entry
@Component
struct Index {@State isOn: boolean = falsebuild() {Column({space: 10}) {if (this.isOn) {Image("pages/images/img_light.png").width(300).height(300)} else {Image("pages/images/img_dark.png").width(300).height(300)}Row({space: 30}) {Button("开灯").onClick(() => this.isOn = true)Button("关灯").onClick(() => this.isOn = false)}}.width("100%").height("100%").justifyContent(FlexAlign.Center)}
}

图标按钮案例

@Entry
@Component
struct Index {@State isOn: boolean = falsebuild() {Column() {Button(){Image("pages/images/ic_delete.png").width(25).height(25)}.width(50).height(50).type(ButtonType.Circle).backgroundColor(Color.Red).onClick(()=>console.log("删除成功"))}.width("100%").height("100%").justifyContent(FlexAlign.Center)}
}

自定义组件案例

@Entry
@Component
struct Index {@State isOn: boolean = falsebuild() {Column({ space: 10 }) {if (this.isOn) {Image("pages/images/img_light.png").width(300).height(300).borderRadius(20)} else {Image("pages/images/img_dark.png").width(300).height(300).borderRadius(20)}Row({ space: 30 }) {GreenButton().onClick(() => this.isOn = true)RedButton().onClick(() => this.isOn = false)}}.width("100%").height("100%").justifyContent(FlexAlign.Center)}
}@Component
struct RedButton {build() {Button({ type: ButtonType.Circle }) {Image("pages/images/icon_switch.png").width(25).height(25)}.width(50).height(50).backgroundColor(Color.Red)}
}@Component
struct GreenButton {build() {Button({ type: ButtonType.Circle }) {Image("pages/images/icon_switch.png").width(25).height(25)}.width(50).height(50).backgroundColor(Color.Green)}
}

自定义组件参数案例

@Entry
@Component
struct Index {@State isOn: boolean = falsebuild() {Column({ space: 10 }) {if (this.isOn) {Image("pages/images/img_light.png").width(300).height(300).borderRadius(20)} else {Image("pages/images/img_dark.png").width(300).height(300).borderRadius(20)}Row({ space: 30 }) {SwitchButton({ color: Color.Green }).onClick(() => this.isOn = true)SwitchButton().onClick(() => this.isOn = false)}}.width("100%").height("100%").justifyContent(FlexAlign.Center)}
}@Component
struct SwitchButton {color: Color = Color.Redbuild() {Button({ type: ButtonType.Circle }) {Image("pages/images/icon_switch.png").width(25).height(25)}.width(50).height(50).backgroundColor(this.color)}
}

组件文件案例

index.ets

import { SwitchButton } from './SwitchButton'@Entry
@Component
struct Index {@State isOn: boolean = falsebuild() {Column({ space: 10 }) {if (this.isOn) {Image("pages/images/img_light.png").width(300).height(300).borderRadius(20)} else {Image("pages/images/img_dark.png").width(300).height(300).borderRadius(20)}Row({ space: 30 }) {SwitchButton({ color: Color.Green }).onClick(() => this.isOn = true)SwitchButton().onClick(() => this.isOn = false)}}.width("100%").height("100%").justifyContent(FlexAlign.Center)}
}

SwitchButton.ets

@Component
export struct SwitchButton {color: Color = Color.Redbuild() {Button({ type: ButtonType.Circle }) {Image("pages/images/icon_switch.png").width(25).height(25)}.width(50).height(50).backgroundColor(this.color)}
}
http://www.lryc.cn/news/445355.html

相关文章:

  • yolo介绍
  • 传输层 II(TCP协议——协议的特点、报文段、连接管理)【★★★★】
  • 质量小议47 - AI写用例
  • etcd 集群搭建与测试指南
  • 写毕业论文用什么软件?分享6款好用的AI论文写作软件网站
  • 【技术解析】wx.request 封装:优化小程序网络请求的最佳实践
  • 9.24 C++ 常成员,运算符重载
  • C#设计模式之访问者模式
  • 一次RPC调用过程是怎么样的?
  • 鸭脖变“刺客”,啃不起了
  • 力扣 —— 删除有序数组中的重复项
  • rmdir :删除空文件夹
  • 网络爬虫Request静态页面数据获取
  • 网页聊天——测试报告——Selenium自动化测试
  • mysql5.7常用操作命令手册
  • 前端组件库Element UI 的使用
  • 【C++ 基础数学 】2121. 2615相同元素的间隔之和|1760
  • 从手动测试菜鸟,到自动化测试老司机,实现自动化落地
  • docker zookeeper集群启动报错:Cannot open channel to * at election address /ip:3888
  • 【Linux探索学习】第一弹——Linux的基本指令(上)——开启Linux学习第一篇
  • 3.Vue2结合element-ui实现国际化多语言i18n
  • 整数二分算法和浮点数二分算法
  • 智能回收箱的功能和使用步骤介绍
  • Remix在SPA模式下,出现ErrorBoundary错误页加载Ant Design组件报错,不能加载样式的问题
  • ADB ROOT开启流程
  • 传输层协议 —— TCP协议(上篇)
  • YOLOv8改进,YOLOv8的Neck替换成AFPN(CVPR 2023)
  • 学习大数据DAY59 全量抽取和增量抽取实战
  • YOLOv8——测量高速公路上汽车的速度
  • 在线相亲交友系统:寻找另一半的新方式