HarmonyOS NEXT 自定义弹框不能全屏?

阅读 611
avatarAI BotBETA
在 HarmonyOS NEXT 中,自定义弹框默认情况下可能不是全屏的。弹框的全屏显示通常取决于其布局和样式设置。如果你希望自定义弹框全屏显示,可以通过调整弹框的布局参数和样式来实现。例如,你可以设置弹框的宽度和高度为匹配父容器的尺寸,或者通过修改相关的布局文件来实现全屏效果。此外,确保没有其他的布局或样式限制导致弹框无法全屏显示。
1 个回答

具体参考demo:

@CustomDialog 
export struct MyDialog1 { 
  controller1: CustomDialogController 
  title: string = '' 
  build() { 
    Row() { 
      Column({ space: 10 }) { 
        Text(this.title).fontSize(25) 
          .fontColor(Color.Blue) 
        Flex({ justifyContent: FlexAlign.SpaceAround }) { 
          Button('取消') 
            .onClick(() => { 
              this.controller1.close() 
            }) 
            .backgroundColor(0xffffff) 
            .fontColor(Color.Black) 
          Button('确认') 
            .onClick(() => { 
              this.controller1.close() 
            }) 
            .backgroundColor(0xffffff) 
            .fontColor(Color.Black) 
        } 
        .width('100%') 
      } 
      .width('100%') 
      .backgroundColor(Color.Gray).height('100%') 
    } 
  } 
} 
// main页面 
@Entry 
@Component 
struct Index { 
  @State dialogData: string = '' 
  @State colorTest: Color = Color.Blue 
  dialogController1: CustomDialogController = new CustomDialogController({ 
    builder: MyDialog1({ 
      title: '弹窗1', 
    }), 
    // 弹窗容器样式是否自定义 
    customStyle: true, 
    offset: { dx: 0, dy: 0 }, 
    alignment: DialogAlignment.Top 
  }) 
 
  confirm(data: string) { 
    this.dialogData = data 
    console.info('ssss') // 获取弹窗输入的信息 
  } 
  build() { 
    Row() { 
      Column({ space: 10 }) { 
        Text('这是一个弹窗的测试') 
          .fontSize(25).margin(20).fontColor(0x3399FF) 
        Button('点击打开弹窗') 
          .onClick(() => { 
            this.dialogController1.open() 
          }) 
      }.width('100%') 
    }.height('100%').backgroundColor(Color.White) 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进