鸿蒙开发:弹窗交互(promptAction )
2024-12-24 22:57:42
139次阅读
0个评论
实现效果
- 点击按钮实现不同方式的弹窗
- showToast
- showDialog
- showActionMenu
代码实现
- 引入'@ohos.promptAction'
import promptAction from '@ohos.promptAction';
- 通过promptAction 实现系统既定的弹窗
import promptAction from '@ohos.promptAction';
@Entry
@Component
struct Show_Page {
@State message: string = 'Hello World';
showToast() {
promptAction.showToast({
message: "登录成功", //显示内容
duration: 2000, //显示持续时间
bottom: 400//设置显示的距离底部位置
})
}
showDialog() {
promptAction.showDialog({
title: "提示",
message: "您确定要删除嘛?",
buttons: [
{
text: "取消",
color: "#000"
},
{
text: "确定",
color: "#000"
}
]
}).then((data) => {
console.log(data.index.toString());
})
}
showActionMenu() {
promptAction.showActionMenu({
title: "选择字体",
buttons: [
{
text: "测试1",
color: "#ccc"
},
{
text: "测试2",
color: "#ccc"
},
{
text: "测试3",
color: "#ccc"
},
{
text: "测试4",
color: "#ccc"
},
{
text: "测试5",
color: "#ccc"
}
]
}).then((data) => {
console.log(data.index.toString());
})
}
build() {
Column() {
Button() {
Text("ShowToast").fontColor(Color.White).fontSize(18)
}
.width("90%")
.height(40)
.margin({ top: 40 })
.onClick(() => {
this.showToast();
})
Button() {
Text("ShowDialog").fontColor(Color.White).fontSize(18)
}
.width("90%")
.height(40)
.margin({ top: 40 })
.onClick(() => {
this.showDialog();
})
Button() {
Text("ShowActionMenu").fontColor(Color.White).fontSize(18)
}
.width("90%")
.height(40)
.margin({ top: 40 })
.onClick(() => {
this.showActionMenu();
})
}
.height('100%')
.width('100%')
}
}
00
- 0回答
- 0粉丝
- 0关注
相关话题
- 鸿蒙开发:实现popup弹窗
- (二六)ArkTS 智能语音交互开发
- (三六)ArkTS 与物联网设备交互开发
- HarmonyOS Next 弹窗系列教程(3)
- HarmonyOS Next 弹窗系列教程(4)
- HarmonyOS Next 弹窗系列教程(5)
- HarmonyOS Next 弹窗系列教程(1)
- HarmonyOS Next 弹窗系列教程(2)
- 自定义组件之<五>自定义对话框(PromptAction)
- Flutter 鸿蒙化 使用 Flutter Channel实现和Flutter和HarmonyOS交互
- (六)ArkTS 与 HarmonyOS 系统交互
- HarmonyNext技术探索:ArkTS在鸿蒙系统中的高级动画与交互设计
- 【HarmonyOS NEXT】 自定义弹窗页面级层级控制解决方案
- (十)HarmonyOS Design 的交互设计基础
- (五五)HarmonyOS Design 的微交互动效