实现promptAction.openCustomDialog接口,全局调用自定义弹窗打开

实现promptAction.openCustomDialog接口,全局调用自定义弹窗打开

HarmonyOS
2024-05-26 15:33:14
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

本文主要用于实现promptAction.openCustomDialog接口,全局调用自定义弹窗打开

使用的核心API

@ohos.promptAction (弹窗)

核心代码解释

#NextPage 
import { customDialogBuilder } from './Page_demo' 
import { promptAction } from '@kit.ArkUI'; 
let customDialogId: number = 0 
​ 
@Entry 
@Component 
struct NextPage { 
@State message: string = 'Hello World'; 
​ 
build() { 
  Row() { 
    Column() { 
      Text(this.message) 
        .fontSize(50) 
        .fontWeight(FontWeight.Bold) 
        .onClick(()=>{ 
          promptAction.openCustomDialog({ 
            builder: customDialogBuilder.bind(this) 
          }).then((dialogId: number) => { 
            customDialogId = dialogId 
          }) 
        }) 
      Button("Click me") 
        .onClick(()=>{ 
          promptAction.openCustomDialog({ 
            builder: customDialogBuilder.bind(this) 
          }).then((dialogId: number) => { 
            customDialogId = dialogId 
          }) 
        }) 
        .margin({top:32}) 
    } 
    .width('100%') 
  } 
  .height('100%') 
} 
} 
#Page_demo 
import promptAction from '@ohos.promptAction' 
let customDialogId: number = 0 
@Builder 
export function customDialogBuilder() { 
Column() { 
  Text('Custom dialog Message').fontSize(20) 
  TextInput() 
  Row() { 
    Button("确认").onClick(() => { 
      promptAction.closeCustomDialog(customDialogId) 
    }) 
    Blank().width(50) 
    Button("取消").onClick(() => { 
      promptAction.closeCustomDialog(customDialogId) 
    }) 
  }.margin({top:80}) 
}.height(200).padding(5) 
} 
​ 
@Entry 
@Component 
struct Index { 
@State message: string = 'Hello World' 
​ 
build() { 
  Row() { 
    Column() { 
      Text(this.message) 
        .fontSize(50) 
        .fontWeight(FontWeight.Bold) 
        .onClick(() => { 
          promptAction.openCustomDialog({ 
            builder: customDialogBuilder.bind(this) 
          }).then((dialogId: number) => { 
            customDialogId = dialogId 
          }) 
        }) 
    } 
    .width('100%') 
  } 
  .height('100%') 
} 
}

实现效果

分享
微博
QQ
微信
回复
2024-05-27 20:35:07
相关问题
promptAction.openCustomDialog 自定义弹窗
498浏览 • 1回复 待解决
promptAction.openCustomDialog 全局弹窗
737浏览 • 1回复 待解决
HarmonyOS promptAction.openCustomDialog问题
89浏览 • 1回复 待解决
HarmonyOS 全局自定义弹窗实现
284浏览 • 1回复 待解决