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

ops/2024/10/19 4:10:22/

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

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

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

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

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.ppmy.cn/ops/118118.html

相关文章

JSP(Java Server Pages)基础使用二

简单练习在jsp页面上输出出乘法口诀表 既然大家都是来看这种代码的人了&#xff0c;那么这种输出乘法口诀表的这种简单算法肯定是难不住大家了&#xff0c;所以这次主要是来说jsp的使用格式问题。 <%--Created by IntelliJ IDEA.User: ***Date: 2024/7/18Time: 11:26To ch…

leetcode每日一题day14(24.9.24)——字符串最多的子序列

思路:对于应该首要和贡献联系起来&#xff0c;对于什么是贡献呢&#xff0c;即在某种情况下&#xff0c;会贡献出多少种&#xff0c;符合要求的结果&#xff0c;此题属于较为基础的&#xff0c;对于text中的一个字符如果是非pattern中的元素&#xff0c;则对结果无任何影响&…

计算机科学(学习笔记四)

早期的编程方式 纸片打孔等方法 汇编语言 编程语言发展史 汇编语言也叫机器语言&#xff0c;是计算机的母语。但01不便于人们操作&#xff0c;人们为了方便操作&#xff0c;会输入文字指令&#xff0c;通过汇编器自动转成二进制指令。 但汇编码和底层硬件仍息息相关&#xff…

Android 开发每日定时任务

1、先注册一个广播 setDailyAlarm();IntentFilter filter3 new IntentFilter("UPDATERULE");registerReceiver(updateRuleReceive, filter3); private BroadcastReceiver updateRuleReceive new BroadcastReceiver() {Overridepublic void onReceive(Context con…

封装聊天组件(fang微信聊天)

用法 图 文 视频还没写好&#xff0c;后期补上&#xff0c;因为基于微博本身的ui框架&#xff0c;所以有的样式会有一些问题&#xff0c;可能跟普通写法有一点不同&#xff0c;但是修改一点就可以 //自己做的假数据 <template><wbx-view style"" click"…

学习和备课数据结构要求----重点*******

目录 要求3&#xff1a;如何学习殷人昆大师的书&#xff1f;&#xff1f;&#xff1f;&#xff1f;&#xff1f; 要求1&#xff1a; 要求2&#xff1a; 要求3&#xff1a; 要求1&#xff1a; 1&#xff09;李冬梅&#xff0c;刘畅 2&#xff09;王红梅教师用书先看老版&a…

uniapp url取消#

hbuilder uniapp取消hash(#)模式 manifest.json "h5": { "template": "static/index.html", "devServer": { "port": 9290, "https": false }, "…

【系统规划与管理师】【案例分析】【考点】【答案篇】第10章 团队建设与管理

【问题篇】☞【系统规划与管理师】【案例分析】【考点】【问题篇】第10章 团队建设与管理 【移动端浏览】☞【系统规划与管理师】【案例分析】【模拟考题】章节考题汇总&#xff08;第10章&#xff09;&#xff08;答案篇&#xff09;&#xff08;共15个知识点&#xff09; 第1…