HarmonyOS Navigation Dialog模式下如何禁用手势返回

官方的这个demo:

// Dialog NavDestination
@Entry
@Component
struct Index {
  @Provide('NavPathStack') pageStack: NavPathStack = new NavPathStack()

  @Builder
  PagesMap(name: string) {
    if (name == 'DialogPage') {
      DialogPage()
    }
  }

  build() {
    Navigation(this.pageStack) {
      Button('Push DialogPage')
        .margin(20)
        .width('80%')
        .onClick(() => {
          this.pageStack.pushPathByName('DialogPage', '');
        })
    }
    .mode(NavigationMode.Stack)
    .title('Main')
    .navDestination(this.PagesMap)
  }
}

@Component
export struct DialogPage {
  @Consume('NavPathStack') pageStack: NavPathStack;

  build() {
    NavDestination() {
      Stack({ alignContent: Alignment.Center }) {
        Column() {
          Text("Dialog NavDestination")
            .fontSize(20)
            .margin({ bottom: 100 })
          Button("Close").onClick(() => {
            this.pageStack.pop()
          }).width('30%')
        }
        .justifyContent(FlexAlign.Center)
        .backgroundColor(Color.White)
        .borderRadius(10)
        .height('30%')
        .width('80%')
      }.height("100%").width('100%')
    }
    .backgroundColor('rgba(0,0,0,0.5)')
    .hideTitleBar(true)
    .mode(NavDestinationMode.DIALOG)
  }
}
  • 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.

在弹窗出现后,怎么禁用手势返回(或者系统导航返回按键)

HarmonyOS
2024-12-25 08:58:47
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

请参考示例如下:

NavDestination() {
  Stack({ alignContent: Alignment.Center }) {
    Column() {
      Text("Dialog NavDestination")
        .fontSize(20)
        .margin({ bottom: 100 })
      Button("Close").onClick(() => {
        this.pageStack.pop()
      }).width('30%')
    }
    .justifyContent(FlexAlign.Center)
    .backgroundColor(Color.White)
    .borderRadius(10)
    .height('30%')
    .width('80%')
  }.height("100%").width('100%')
}
.backgroundColor('rgba(0,0,0,0.5)')
.hideTitleBar(true)
.mode(NavDestinationMode.DIALOG)
.onBackPressed(() => {
  console.log('自定义操作')
  return true
})
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
分享
微博
QQ
微信
回复
2024-12-25 10:04:49
相关问题
HarmonyOS 如何禁用页面返回手势
941浏览 • 1回复 待解决
如何禁用系统左右手势返回
866浏览 • 1回复 待解决
HarmonyOS 禁用滑动返回手势问题
699浏览 • 1回复 待解决
HarmonyOS 如何禁用深色模式
599浏览 • 1回复 待解决
HarmonyOS app内如何禁用深色模式
927浏览 • 1回复 待解决
HarmonyOS 如何禁用小窗和分屏模式
1192浏览 • 1回复 待解决
HarmonyOS 怎么禁用分屏模式
534浏览 • 1回复 待解决
CustomDialogController禁用返回
964浏览 • 1回复 待解决
HarmonyOS HMRouter使用 Dialog模式
776浏览 • 0回复 待解决
HarmonyOSNavigation显示dialog问题
1421浏览 • 1回复 待解决
HarmonyOS Navigation实现Dialog转场动画
711浏览 • 1回复 待解决
HarmonyOS 页面如何禁止手势返回
856浏览 • 1回复 待解决
HarmonyOS 怎样在工程中禁用深色模式
658浏览 • 1回复 待解决
HarmonyOS dialog如何禁止侧滑返回关闭
677浏览 • 1回复 待解决