实现二次侧滑退出应用

实现二次侧滑退出应用

HarmonyOS
2024-05-06 22:32:21
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
电子土豆片
import common from "@ohos.app.ability.common"; 
import { promptAction } from "@kit.ArkUI"; 
 
@Entry 
@Component 
struct IndexComponent { 
  @State textColor: Color = Color.Black; 
 
  onPageShow() { 
    this.textColor = Color.Blue; 
    console.info("IndexComponent onPageShow"); 
  } 
 
  onPageHide() { 
    this.textColor = Color.Transparent; 
    console.info("IndexComponent onPageHide"); 
  } 
 
  firstBcakTimestamp: number = 0; 
 
  onBackPress() { 
    console.info("IndexComponent onBackPress"); 
    this.textColor = Color.Red; 
    let now = Date.now(); 
    if (now - this.firstBcakTimestamp < 1000) { 
      const context = getContext(this) as common.UIAbilityContext 
      context.terminateSelf(); // 终止程序 
    } else { 
      this.firstBcakTimestamp = now; 
      let option: promptAction.ShowToastOptions = { 
        message: "是否继续退出"// 可以是$r图片 
      } 
      promptAction.showToast(option); 
    } 
    return true 
  } 
 
  build() { 
    Column() { 
      Text("Hello World") 
        .fontColor(this.textColor) 
        .fontSize(30) 
        .margin(30) 
    }.width("100%") 
  } 
}
  • 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.
分享
微博
QQ
微信
回复
2024-05-07 15:25:51
相关问题
HarmonyOS aioxs二次封装
1048浏览 • 1回复 待解决
HarmonyOS 权限二次申请
906浏览 • 1回复 待解决
HarmonyOS getStringByName方法二次封装
1054浏览 • 1回复 待解决
class二次刷新渲染数组
1599浏览 • 1回复 待解决
HarmonyOS 退出问题
914浏览 • 1回复 待解决
HarmonyOS cocos引擎能否二次启动
1269浏览 • 1回复 待解决
华为账号实时验证/二次放号相关咨询
2925浏览 • 1回复 待解决