HarmonyOS 全局自定义弹窗demo

HarmonyOS 全局自定义弹窗demo。

HarmonyOS
2024-10-12 09:28:09
1185浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

参考demo如下:

export class Params {  
  text: string = ""  
  callback: (volumeType: string, value: number) => void = () => {  
  };  
  constructor(text: string, callback: (volumeType: string, value: number) => void) {  
    this.text = text;  
    this.callback = callback;  
  }  
}  
@Builder  
export function buildText(params: Params) {  
  Column() {  
    Text(params.text)  
      .fontSize(50)  
      .fontWeight(FontWeight.Bold)  
      .margin({bottom: 36})  
  }.backgroundColor('#FFF0F0F0')  
}  
@Entry  
@Component  
struct CustomDialog_Globally {  
  @State message: string = "hello"  
  
  build() {  
    Row() {  
      Column() {  
        Button("click me")  
          .onClick(() => {  
            let uiContext = this.getUIContext();  
            let promptAction = uiContext.getPromptAction();  
          })  
      }  
      .width('100%')  
      .height('100%')  
    }  
    .height('100%')  
  }  
}
import { ComponentContent } from '@kit.ArkUI';  
import { BusinessError } from '@kit.BasicServicesKit';  
import { buildText, Params } from './CustomDialog_Globally';  
@Entry  
@Component  
struct CustomDialog_Globally_other01 {  
  @State message: string = 'Hello World';  
  build() {  
    Column() {  
      Text(this.message)  
        .id('HelloWorld')  
        .fontSize(50)  
        .fontWeight(FontWeight.Bold)  
        .onClick(() => {  
          let uiContext = this.getUIContext();  
          let promptAction = uiContext.getPromptAction();  
          let callback = (volumeType: string, value: number) => {  
            //处理返回值的逻辑  
            console.log(`OpenCustomDialog args error code is ${volumeType}, message is ${value}`);  
            this.message = volumeType;  
          }  
          let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message, callback));  
          try {  
            promptAction.openCustomDialog(contentNode);  
          } catch (error) {  
            let message = (error as BusinessError).message;  
            let code = (error as BusinessError).code;  
            console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);  
          };  
        })  
    }  
    .height('100%')  
    .width('100%')  
  }  
}
import { BusinessError } from '@ohos.base';  
import { ComponentContent } from "@ohos.arkui.node";  
class Params {  
  text: string = ""  
  constructor(text: string) {  
    this.text = text;  
  }  
}  
@Builder  
function buildText(params: Params) {  
  Column() {  
    Text(params.text)  
      .fontSize(50)  
      .fontWeight(FontWeight.Bold)  
      .margin({bottom: 36})  
    TextInput()  
  }.backgroundColor('#FFF0F0F0')  
  .margin({  
    bottom: -16  
  })  
}  
@Entry  
@Component  
struct CustomDialog_Xuzhip {  
  @State message: string = "hello"  
  build() {  
    Row() {  
      Column() {  
        Button("click me")  
          .onClick(() => {  
            let uiContext = this.getUIContext();  
            let promptAction = uiContext.getPromptAction();  
            let contentNode = new ComponentContent(uiContext, wrapBuilder(buildText), new Params(this.message));  
            try {  
              promptAction.openCustomDialog(contentNode);  
            } catch (error) {  
              let message = (error as BusinessError).message;  
              let code = (error as BusinessError).code;  
              console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);  
            };  
          })  
      }  
      .width('100%')  
      .height('100%')  
    }  
    .height('100%')  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
分享
微博
QQ
微信
回复
2024-10-12 17:10:01
相关问题
HarmonyOS 使用全局自定义弹窗
763浏览 • 1回复 待解决
HarmonyOS 全局自定义弹窗无法弹出
821浏览 • 1回复 待解决
HarmonyOS 全局自定义弹窗的实现
899浏览 • 1回复 待解决
HarmonyOS 如何创建自定义全局弹窗
736浏览 • 1回复 待解决
如何封装全局性的自定义弹窗
964浏览 • 1回复 待解决
HarmonyOS 全局弹窗demo
584浏览 • 1回复 待解决
HarmonyOS 非ui界面拉起自定义弹窗demo
1042浏览 • 1回复 待解决
HarmonyOS 自定义全局dialog
689浏览 • 1回复 待解决
HarmonyOS 全局自定义字体
781浏览 • 1回复 待解决
HarmonyOS 全局自定义字体
826浏览 • 1回复 待解决
自定义弹窗自定义转场动画
1930浏览 • 1回复 待解决
如何在全局实现一个自定义dialog弹窗
3643浏览 • 1回复 待解决
HarmonyOS 自定义相机demo
1586浏览 • 1回复 待解决
HarmonyOS 自定义弹窗选择
1289浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog
744浏览 • 1回复 待解决