HarmonyOS 如何拦截系统返回,实现返回时提示二次确认弹窗

HarmonyOS 如何拦截系统返回,实现返回时提示二次确认弹窗

HarmonyOS
2024-08-30 09:40:53
874浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

Demo如下

import {  MarkerOptions } from '@amap/amap_lbs_map3d'; 
import { HomeComponent, StationDetailPage } from 'home/Index'; 
import { MapViewContainer } from 'map/Index'; 
import { CustomTabBar } from '../components/CustomTabBar'; 
import { AppConstants } from '../constants/AppConstants'; 
import { PersonInfo } from 'user/Index'; 
import { promptAction, ShowDialogSuccessResponse } from '@kit.ArkUI'; 
import { common } from '@kit.AbilityKit'; 
 
@Entry 
@Component 
struct Index { 
  @Provide('appPathStack') appPathStack: NavPathStack = new NavPathStack(); 
  @State currentIndex: number = 0 
  context = getContext(this) as common.UIAbilityContext 
  aboutToAppear(): void { 
  } 
  @Builder 
  PageMap(name: string) { 
    if (name === 'homePage') { 
      HomeComponent() 
    }else if (name === 'stationDetailPage'){ 
      StationDetailPage() 
    }else if (name === 'userPersonInfo'){ 
      HomeComponent() 
    } 
  } 
  build() { 
    Navigation(this.appPathStack) { 
      Stack() { 
        Flex({ 
          direction: FlexDirection.Column, 
        }) { 
          Tabs({ index: this.currentIndex }) { 
            TabContent() { 
              HomeComponent() 
            } 
        TabContent() { 
          MapViewContainer() 
        } 
 
        TabContent() { 
          // ChallengeView() 
        }.tabBar() 
 
        TabContent() { 
          // ActivityView({ webViewController: $webViewController }) 
        } 
 
        TabContent() { 
          PersonInfo() 
        } 
      } 
      .layoutWeight(1) 
      .barHeight(0) 
      .scrollable(false) 
      .onChange((index) => { 
        this.currentIndex = index; 
      }) 
 
      CustomTabBar({ currentIndex: $currentIndex }) 
    } 
    .width(AppConstants.FULL_PERCENT) 
    .height(AppConstants.FULL_PERCENT) 
    .backgroundColor($r('app.color.common_background_color')) 
  } 
} 
.hideTitleBar(true) 
.navDestination(this.PageMap) 
.mode(NavigationMode.Stack) 
 
  } 
  onBackPress() { 
    console.info('onBackPress:'); 
    promptAction.showDialog({ 
      title: "提示", 
      message: "确认退出?", 
      buttons: [ 
        { 
          text: "取消", 
          color: "#000000" 
        }, 
        { 
          text: "退出", 
          color: "#555555" 
        } 
      ] 
    }).then((data: ShowDialogSuccessResponse) => { 
      console.info('showDialog success, click button: ' + data.index); 
      if (data.index == 1) { 
        this.context.terminateSelf() 
      } 
    }) 
    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.
  • 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.
分享
微博
QQ
微信
回复
2024-08-30 20:17:44


相关问题
HarmonyOS 系统返回如何拦截
676浏览 • 1回复 待解决
实现二次侧滑退出应用
2772浏览 • 1回复 待解决
HarmonyOS 弹窗如何拦截返回
676浏览 • 1回复 待解决
HarmonyOS 权限二次申请
838浏览 • 1回复 待解决
HarmonyOS aioxs二次封装
988浏览 • 1回复 待解决
HarmonyOS getStringByName方法二次封装
982浏览 • 1回复 待解决
HarmonyOS cocos引擎能否二次启动
1201浏览 • 1回复 待解决
class二次刷新渲染数组
1539浏览 • 1回复 待解决
HarmonyOS 在Page中如何拦截系统返回
587浏览 • 1回复 待解决
HarmonyOS UIAbility 侧滑如何拦截返回
636浏览 • 1回复 待解决
HarmonyOS 拦截系统返回手势问题
1534浏览 • 1回复 待解决
HarmonyOS 拍照无法确认返回
667浏览 • 1回复 待解决
HarmonyOS 全模态怎么拦截系统返回
572浏览 • 1回复 待解决
HarmonyOS 如何拦截物理返回
600浏览 • 1回复 待解决
HarmonyOS 如何拦截UIAbility的返回
488浏览 • 1回复 待解决
华为账号实时验证/二次放号相关咨询
2852浏览 • 1回复 待解决
HarmonyOS 返回及侧滑返回无法拦截事件
1270浏览 • 1回复 待解决