【问题标题】:Click back button to show toast notification and on click again it should exit the app单击后退按钮以显示 toast 通知,再次单击它应该退出应用程序
【发布时间】:2019-11-06 22:55:21
【问题描述】:

我正在创建我的科尔多瓦应用程序,点击移动应用程序中的默认后退按钮时,它应该显示一个烤面包机通知“再次点击以退出应用程序”,然后再次点击后退按钮它应该退出应用程序。

我尝试了一些代码,但似乎没有一个代码在应用程序中起作用。

window.plugins.toast.showWithOptions(
    {
      message: "Tap again to exit the app",
      duration: 1500, // ms
      position: "bottom",
      addPixelsY: -40,  // (optional) added a negative value to move it up a bit (default 0)
      data: {'foo':'bar'} // (optional) pass in a JSON object here (it will be sent back in the success callback below)
    },
    // implement the success callback
    function(result) {
      if (result && result.event) {
        console.log("The toast was tapped or got hidden, see the value of result.event");
        console.log("Event: " + result.event); // "touch" when the toast was touched by the user or "hide" when the toast geot hidden
        console.log("Message: " + result.message); // will be equal to the message you passed in
        console.log("data.foo: " + result.data.foo); // .. retrieve passed in data here

        if (result.event === 'hide') {
          console.log("The toast has been shown");
        }
      }
    }
  );

预期结果:单击移动应用程序中的默认返回按钮时,应显示“Tap again to exit the app”的烤面包机通知,然后再次单击返回按钮应退出应用程序。 实际结果:没有显示任何 toast 通知消息。

【问题讨论】:

    标签: android jquery cordova toast back-button


    【解决方案1】:

    你可以像这样创建你的逻辑:

    int isTouched = false;
    
    public void btnClick(View view){
    
      if(isButtonTouched)//exit 
      else isButtonTouched=true(and show your toast)
    
    }

    【讨论】:

      猜你喜欢
      • 2012-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多