HarmonyOS 自定义弹窗部分问题答疑

1、使用自定义弹窗时,希望拦截返回键不隐藏。

2、自定义弹窗展示怎么遮盖住底部导航条。

HarmonyOS
2024-10-18 10:03:38
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

问题1:目前想要实现防止用户侧滑关闭自定义弹窗的效果需要基于Navigation实现自定义弹窗,然后设置.onBackPressed((): boolean => true)。

@Component  
struct Dialog01 {  
  @Consume('pageInfos') pageInfos: NavPathStack;  
  build() {  
    NavDestination() {  
      Stack() {  
        Column()  
          .width('100%')  
          .height('100%')  
          .backgroundColor(Color.Gray)  
          .opacity(0.1)  
        // Add controls for business processing  
        Column() {  
          Text('Dialog01')  
            .fontSize(30)  
            .fontWeight(2)  
        }  
        .padding(10)  
        .width(250)  
        .backgroundColor(Color.White)  
        .borderRadius(10)  
      }  
    }  
    .onBackPressed((): boolean => true)  
    .hideTitleBar(true)  
    // Set the mode property of this NavDestination to DIALOG  
    .mode(NavDestinationMode.DIALOG)  
  }  
}  
@Entry  
@Component  
struct Index {  
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()  
  isLogin: boolean = false;  
  
  @Builder  
  PagesMap(name: string) {  
    if (name == 'Dialog01') {  
      Dialog01()  
    }  
  }  
  build() {  
    Navigation(this.pageInfos) {  
      Button('push Dialog01')  
        .width('80%')  
        .onClick(() => {  
          this.pageInfos.pushPathByName('Dialog01', '');  
        })  
    }  
    .mode(NavigationMode.Stack)  
    .titleMode(NavigationTitleMode.Mini)  
    .title('主页')  
    .navDestination(this.PagesMap)  
  }  
}
  • 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.

问题2:可以修改offset和alignment这俩属性的值实现,类似这样。

   alignment: DialogAlignment.Bottom,       
    offset: { dx: -2, dy: 0 }
  • 1.
  • 2.
分享
微博
QQ
微信
回复
2024-10-18 18:22:33


相关问题
HarmonyOS 自定义弹窗CustomDialog问题
1041浏览 • 1回复 待解决
HarmonyOS 自定义弹窗控制问题
660浏览 • 1回复 待解决
HarmonyOS 自定义弹窗问题
1327浏览 • 1回复 待解决
HarmonyOS 自定义弹窗层级问题
639浏览 • 1回复 待解决
HarmonyOS 自定义弹窗关闭问题
546浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog 问题
468浏览 • 1回复 待解决
HarmonyOS 自定义弹窗 (CustomDialog)问题
986浏览 • 1回复 待解决
HarmonyOS 自定义弹窗封装问题
566浏览 • 1回复 待解决
自定义弹窗使用相关问题
1410浏览 • 1回复 待解决
HarmonyOS 自定义弹窗刷新问题
392浏览 • 1回复 待解决
HarmonyOS 自定义弹窗不能显示问题
540浏览 • 1回复 待解决
HarmonyOS 自定义弹窗点击跳转问题
492浏览 • 1回复 待解决
自定义弹窗自定义转场动画
1633浏览 • 1回复 待解决
HarmonyOS 自定义弹窗初始化问题
425浏览 • 1回复 待解决
HarmonyOS 自定义弹窗选择
974浏览 • 1回复 待解决
HarmonyOS 自定义弹窗CustomDialog
486浏览 • 1回复 待解决
HarmonyOS 使用全局自定义弹窗
522浏览 • 1回复 待解决