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

鸿蒙(HarmonyOS)项目方舟框架(ArkUI)控件的部分公共属性和事件

鸿蒙(HarmonyOS)项目方舟框架(ArkUI)控件的部分公共属性和事件

一、操作环境

操作系统:  Windows 10 专业版

IDE:DevEco Studio 3.1

SDK:HarmonyOS 3.1

二、公共属性

常用的公共属性有:

宽(with)、高(height)、尺寸(size)、背景色(backgroudColor)、

Text().size({width: 220, height: 125}) // 设置宽高.width(120)                      // 设置宽度,覆盖前边的值.height(25)                      // 设置高度,覆盖前边的值.backgroundColor("#ccbbaa")      // 设置背景色

设置组件的宽高,缺省时使用组件自身内容的宽高,比如充满父布局可以使用 string 值:"100%",当组件同时设置 size 和 width / height 时,以最后设置的值为准。

外边距(padding)、内边距(margin)、

Stack() {Text().width('100%')               // 设置宽度充满父布局.height('100%')              // 设置高度充满父布局.backgroundColor(Color.Pink) // 设置背景色
}
.padding(10)                     // 设置四个边距值
.backgroundColor("#aabbcc")      // 设置背景色
.size({width: 80, height: 80})   // 设置宽高尺寸Stack() {Text().width('100%')               // 宽度充满父布局.height('100%')              // 高度充满父布局.backgroundColor(Color.Pink) // 设置背景色
}
.padding({left: 5, top: 20, right: 5, bottom: 20})// 设置不同的边距值
.backgroundColor("#aabbcc")                       // 设置背景色
.size({width: 80, height: 80})                    // 设置宽高尺寸

权重(layoutWeight)、对齐方式(align)、布局方向(direction对应的枚举
Ltr,Rtl,Auto)、相对定位(offset)、绝对定位(position)、

显示隐藏(visibility对应的枚举Visible,Hidden,None)

Row() {Text().height(30).width(120).backgroundColor("#aabbcc").layoutWeight(1)Text().height(30).backgroundColor("#aaccbb").visibility(Visibility.Visible) // 设置默认值Visible.layoutWeight(1)Text().height(30).backgroundColor(Color.Pink).layoutWeight(1)
}Row() {Text().height(30).width(120).backgroundColor("#aabbcc").layoutWeight(1)Text().height(30).backgroundColor("#aaccbb").visibility(Visibility.Hidden) // 设置Hidden,不在界面显示但是还占着位置.layoutWeight(1)Text().height(30).backgroundColor(Color.Pink).layoutWeight(1)
}Row() {Text().height(30).backgroundColor("#aabbcc").layoutWeight(1)Text().height(30).visibility(Visibility.None) // 设置None,不在界面上显示.backgroundColor("#aaccbb").layoutWeight(1)Text().height(30).backgroundColor(Color.Pink).layoutWeight(1)
}

三、公共事件

常用的公共事件:

点击事件(onClick)

Text('Click 亚丁号').width(120).height(40).backgroundColor(Color.Pink)      // 设置背景颜色.onClick(() => {                  // 设置点击事件回调console.log("text clicked 亚丁号") // 日志输出})

获得焦点事件、失去焦点事件

@Entry @Component struct ComponentTest {@State textOne: string = ''@State textTwo: string = ''@State textThree: string = ''@State oneButtonColor: string = '#FF0000'@State twoButtonColor: string = '#87CEFA'@State threeButtonColor: string = '#90EE90'build() {Column({ space: 10 }) {Button(this.textOne).backgroundColor(this.oneButtonColor).width(260).height(70).fontColor(Color.Black).focusable(true).onFocus(() => {this.textOne = 'First Button onFocus'this.oneButtonColor = '#AFEEEE'}).onBlur(() => {this.textOne = 'First Button onBlur'this.oneButtonColor = '#FFC0CB'})Button(this.textTwo).backgroundColor(this.twoButtonColor).width(260).height(70).fontColor(Color.Black).focusable(true)Button(this.textThree).backgroundColor(this.threeButtonColor).width(260).height(70).fontColor(Color.Black).focusable(true).onFocus(() => {this.textThree = 'Third Button onFocus'this.threeButtonColor = '#AFEEEE'}).onBlur(() => {this.textThree = 'Third Button onBlur'this.threeButtonColor = '#FFC0CB'})}.width('100%').height('100%').padding(10)}
}

目前支持焦点事件的组件:Button、 TextImage、 List、 Grid

好了就写到这吧!

你有时间常去我家看看我在这里谢谢你啦...

我家地址:亚丁号

最后送大家一首诗:

山高路远坑深,
大军纵横驰奔,

谁敢横刀立马?
惟有点赞加关注大军。

http://www.lryc.cn/news/262364.html

相关文章:

  • 最新同步云盘推荐:实现轻松管理与便捷同步的理想选择
  • (第27天)Oracle 数据泵转换分区表
  • 业务上需要顺序消费,怎么保证时序性?
  • ubuntu 开机提示 you are in emergency mode,journalctl -xb
  • 【Hadoop面试】HDFS读写流程
  • B01、JVM与Java体系结构-01
  • Python:Jupyter
  • macos苹果电脑开启tftp server上传fortigate60e固件成功
  • 如何使用ArcGIS Pro裁剪影像
  • Tekton 构建容器镜像
  • netty-daxin-4(httpwebsocket)
  • 文章解读与仿真程序复现思路——电力系统自动化EI\CSCD\北大核心《市场环境下考虑全周期经济效益的工业园区共享储能优化配置》
  • WPF——命令commond的实现方法
  • 信息收集 - 域名
  • 基于YOLOv8深度学习的路面标志线检测与识别系统【python源码+Pyqt5界面+数据集+训练代码】目标检测、深度学习实战
  • leetCode算法—1.两数之和
  • oracle 设置访问白名单
  • Flink系列之:窗口关联
  • Eolink 两项产品入选 2023 年广东省名优高新技术产品名录!
  • 054:vue工具 --- BASE64加密解密互相转换
  • 自动驾驶学习笔记(二十)——Planning算法
  • adb的使用
  • 会旋转的树,你见过吗?
  • Azure Machine Learning - 提示工程简介
  • 服务器的安全包括哪些方面?服务器安全该如何去加固处理?
  • 为什么在Android中需要Context?
  • AIGC实战——条件生成对抗网络(Conditional Generative Adversarial Net, CGAN)
  • 高性能计算HPC与统一存储
  • 秋招上岸记录咕咕咕了。
  • vue模板语法