IT评测·应用市场-qidao123.com
标题:
鸿蒙Harmony应用开发—ArkTS-全局UI方法(警告弹窗)
[打印本页]
作者:
大连全瓷种植牙齿制作中心
时间:
2024-6-10 16:04
标题:
鸿蒙Harmony应用开发—ArkTS-全局UI方法(警告弹窗)
通过CustomDialogController类显示自界说弹窗。使用弹窗组件时,可优先考虑自界说弹窗,便于自界说弹窗的样式与内容。
阐明:
从API Version 7开始支持。后续版本如有新增内容,则接纳上角标单独标记该内容的起始版本。
接口
CustomDialogController(value:{builder: CustomDialog, cancel?: () => void, autoCancel?: boolean, alignment?: DialogAlignment, offset?: Offset, customStyle?: boolean, gridCount?: number, maskColor?: ResourceColor, maskRect?: Rectangle, openAnimation?: AnimateParam, closeAniamtion?: AnimateParam, showInSubWindow?: boolean, backgroundColor?:ResourceColor, cornerRadius?
imension | BorderRadiuses})
参数:
参数名参数类型必填参数形貌builderCustomDialog是自界说弹窗内容构造器。cancel() => void否点击遮障层退出时的回调。autoCancelboolean否是否答应点击遮障层退出。
默认值:truealignmentDialogAlignment否弹窗在竖直方向上的对齐方式。
默认值:DialogAlignment.DefaultoffsetOffset否弹窗相对alignment所在位置的偏移量。customStyleboolean否弹窗容器样式是否自界说。
默认值:false,弹窗容器的宽度根据栅格体系自适应,不跟随子节点;高度自适应子节点,最大为窗口高度的90%;圆角为24vp。gridCount8+number否弹窗宽度占栅格宽度的个数。
默以为按照窗口大小自适应,非常值按默认值处理,最大栅格数为体系最大栅格数。maskColor10+ResourceColor否自界说蒙层颜色。
默认值: 0x33000000maskRect10+Rectangle否弹窗掩藏层区域,在掩藏层区域内的事件不透传,在掩藏层区域外的事件透传。
默认值:{ x: 0, y: 0, width: '100%', height: '100%' }openAnimation10+AnimateParam否自界说设置弹窗弹出的动画效果相干参数。
阐明
:
iterations默认值为1,默认播放一次,设置为其他数值时按默认值处理。
playMode控制动画播放模式,默认值为PlayMode.Normal,设置为其他数值时按照默认值处理。closeAniamtion10+AnimateParam否自界说设置弹窗关闭的动画效果相干参数。
阐明
:
iterations默认值为1,默认播放一次,设置为其他数值时按默认值处理。
playMode控制动画播放模式,默认值为PlayMode.Normal,设置为其他数值时按照默认值处理。showInSubWindow10+boolean否某弹框必要显示在主窗口之外时,是否在子窗口显示此弹窗。
默认值:false,在子窗口不显示弹窗。
阐明
:showInSubWindow为true的弹窗无法触发显示另一个showInSubWindow为true的弹窗。backgroundColor10+ResourceColor否设置弹窗背板添补。
阐明
:如果同时设置了内容构造器的背景致,则backgroundColor会被内容构造器的背景致覆盖。cornerRadius10+BorderRadiuses | Dimension否设置背板的圆角半径。
可分别设置4个圆角的半径。
默认值:{ topLeft: '24vp', topRight: '24vp', bottomLeft: '24vp', bottomRight: '24vp' }
阐明
:自界说弹窗默认的背板圆角半径为24vp,如果必要使用cornerRadius属性,请和borderRadius属性一起使用。
CustomDialogController
导入对象
let dialogController : CustomDialogController = new CustomDialogController(...)
复制代码
阐明
:CustomDialogController仅在作为@CustomDialog和@Component struct的成员变量,且在@Component struct内部界说时赋值才有用,具体用法可看下方示例。
open
open(): void
显示自界说弹窗内容,答应多次使用,但如果弹框为SubWindow模式,则该弹框不答应再弹出SubWindow弹框。
close
close(): void
关闭显示的自界说弹窗,若已关闭,则不生效。
示例
// xxx.ets
@CustomDialog
struct CustomDialogExampleTwo {
controllerTwo?: CustomDialogController
build() {
Column() {
Text('我是第二个弹窗')
.fontSize(30)
.height(100)
Button('点我关闭第二个弹窗')
.onClick(() => {
if (this.controllerTwo != undefined) {
this.controllerTwo.close()
}
})
.margin(20)
}
}
}
@CustomDialog
struct CustomDialogExample {
@Link textValue: string
@Link inputValue: string
dialogControllerTwo: CustomDialogController | null = new CustomDialogController({
builder: CustomDialogExampleTwo(),
alignment: DialogAlignment.Bottom,
offset: { dx: 0, dy: -25 } })
controller?: CustomDialogController
// 若尝试在CustomDialog中传入多个其他的Controller,以实现在CustomDialog中打开另一个或另一些CustomDialog,那么此处需要将指向自己的controller放在所有controller的后面
cancel: () => void = () => {
}
confirm: () => void = () => {
}
build() {
Column() {
Text('Change text').fontSize(20).margin({ top: 10, bottom: 10 })
TextInput({ placeholder: '', text: this.textValue }).height(60).width('90%')
.onChange((value: string) => {
this.textValue = value
})
Text('Whether to change a text?').fontSize(16).margin({ bottom: 10 })
Flex({ justifyContent: FlexAlign.SpaceAround }) {
Button('cancel')
.onClick(() => {
if (this.controller != undefined) {
this.controller.close()
this.cancel()
}
}).backgroundColor(0xffffff).fontColor(Color.Black)
Button('confirm')
.onClick(() => {
if (this.controller != undefined) {
this.inputValue = this.textValue
this.controller.close()
this.confirm()
}
}).backgroundColor(0xffffff).fontColor(Color.Red)
}.margin({ bottom: 10 })
Button('点我打开第二个弹窗')
.onClick(() => {
if (this.dialogControllerTwo != null) {
this.dialogControllerTwo.open()
}
})
.margin(20)
}.borderRadius(10)
// 如果需要使用border属性或cornerRadius属性,请和borderRadius属性一起使用。
}
}
@Entry
@Component
struct CustomDialogUser {
@State textValue: string = ''
@State inputValue: string = 'click me'
dialogController: CustomDialogController | null = new CustomDialogController({
builder: CustomDialogExample({
cancel: this.onCancel,
confirm: this.onAccept,
textValue: $textValue,
inputValue: $inputValue
}),
cancel: this.existApp,
autoCancel: true,
alignment: DialogAlignment.Bottom,
offset: { dx: 0, dy: -20 },
gridCount: 4,
customStyle: false,
backgroundColor: 0xd9ffffff,
cornerRadius: 10,
})
// 在自定义组件即将析构销毁时将dialogControlle置空
aboutToDisappear() {
this.dialogController = null // 将dialogController置空
}
onCancel() {
console.info('Callback when the first button is clicked')
}
onAccept() {
console.info('Callback when the second button is clicked')
}
existApp() {
console.info('Click the callback in the blank area')
}
build() {
Column() {
Button(this.inputValue)
.onClick(() => {
if (this.dialogController != null) {
this.dialogController.open()
}
}).backgroundColor(0x317aff)
}.width('100%').margin({ top: 5 })
}
}
复制代码
末了
有很多小同伴不知道学习哪些鸿蒙开发技术?不知道必要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,终极浪费大量时间。以是有一份实用的
鸿蒙(HarmonyOS NEXT)资料
用来跟着学习黑白常有必要的。
这份鸿蒙(HarmonyOS NEXT)资料包罗了鸿蒙开发必掌握的核心知识要点,内容包罗了
(
ArkTS、ArkUI开发组件、Stage模型、多端摆设、分布式应用开发、音频、视频、WebGL、OpenHarmony
多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)
技术知识点。
希望这一份鸿蒙学习资料能够给各人带来帮助,有必要的小同伴自行领取,
限时开源,先到先得~无套路领取!!
获取这份完备版高清学习门路,请点击→
纯血版全套鸿蒙HarmonyOS学习资料
鸿蒙(HarmonyOS NEXT)最新学习门路
HarmonOS基础技能
HarmonOS就业必备技能
HarmonOS多媒体技术
鸿蒙NaPi组件进阶
HarmonOS高级技能
初识HarmonOS内核
实战就业级装备开发
有了门路图,怎么能没有学习资料呢,小编也预备了一份团结鸿蒙官方发布条记整理收纳的一套体系性的
鸿蒙(OpenHarmony )学习手册(共计1236页)
与
鸿蒙(OpenHarmony )开发入门教学视频
,内容包罗:
ArkTS、ArkUI、Web开发、应用模型、资源分类…等知识点。
获取以上完备版高清学习门路,请点击→
纯血版全套鸿蒙HarmonyOS学习资料
《鸿蒙 (OpenHarmony)开发入门教学视频》
《鸿蒙生态应用开发V2.0白皮书》
《鸿蒙 (OpenHarmony)开发基础到实战手册》
OpenHarmony北向、南向开发环境搭建
《鸿蒙开发基础》
ArkTS语言
安装DevEco Studio
运用你的第一个ArkTS应用
ArkUI声明式UI开发
.……
《鸿蒙开发进阶》
Stage模型入门
网络管理
数据管理
电话服务
分布式应用开发
关照与窗口管理
多媒体技术
安全技能
任务管理
WebGL
国际化开发
应用测试
DFX面向未来操持
鸿蒙体系移植和裁剪定制
……
《鸿蒙进阶实战》
ArkTS实践
UIAbility应用
网络案例
……
获取以上完备鸿蒙HarmonyOS学习资料,请点击→
纯血版全套鸿蒙HarmonyOS学习资料
总结
总的来说,华为鸿蒙不再兼容安卓,对中年程序员来说是一个挑衅,也是一个机遇。只有积极应对变化,不断学习和提拔自己,他们才气在这个变革的时代中立于不败之地。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/)
Powered by Discuz! X3.4