在HarmonyOS NEXT中 promptAction.openCustomDialog 弹窗宽度设置全屏宽的方法?

阅读 637
1 个回答

目前promptAction.openCustomDialog 设置width(‘100%’), 系统会默认所在窗口宽度 - 左右 16vp
width参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-refere...

demo:

import promptAction from '@ohos.promptAction'; 
import display from '@ohos.display' 
 
@Entry 
@Component 
struct Index { 
  @State message: string = 'Hello World'; 
 
  build() { 
    Button('点我').onClick(() => { 
      DialogUtils.show(this) 
    }) 
  } 
} 
 
@Component 
export struct TestComponent { 
  build() { 
    Row() { 
      Text('弹窗内组件1弹窗内组件2弹窗内组件3弹窗内组件4弹窗内组件5弹窗内组件') 
        .height(200) 
        .textAlign(TextAlign.Center) 
    } 
  } 
} 
 
export class DialogUtils { 
  public static createOption(builder: CustomBuilder) { 
    const option: promptAction.CustomDialogOptions = { 
      builder: builder, 
      isModal: true, 
      alignment: DialogAlignment.Bottom, 
      cornerRadius: 0, 
      backgroundColor: Color.Red, 
      width: "110%", 
      autoCancel: false, 
    } 
    return option 
  } 
 
  public static show(context: Object,) { 
    promptAction.openCustomDialog(DialogUtils.createOption(buildComp.bind(context))) 
  } 
} 
 
@Builder 
function buildComp() { 
  TestComponent() 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进