科尔多瓦后退按钮不起作用

时间:2018-06-17 08:40:40

标签: javascript android jquery cordova phonegap-plugins

这是我尝试编程的第一个Android应用程序,所以我是这个领域的初学者。我的应用正在使用JQuery并且有一个故事列表。除了后退按钮,一切都很好,工作正常。如果我穿过故事,然后按后退按钮它会一直向后,直到开始,我想按下后退按钮退出应用程序。

我遵循了这个主题:https://cordova.apache.org/docs/en/latest/cordova/events/events.html#backbutton

和这个主题: https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin#4-usage

也是这样的: https://pointdeveloper.com/how-to-double-tap-exit-for-ionic-apps/

但是,我仍然不能让后退按钮工作。

正如我所说,我是初学者,有一个解释的例子对我来说会更好,所以我知道我需要编辑代码。

在jquery-1.12.4.js中我添加了这些行:

 function showBottom() {
  window.plugins.toast.showWithOptions(
    {
      message: "hey there",
      duration: "short", // which is 2000 ms. "long" is 4000. Or specify the nr of ms yourself.
      position: "bottom",
      addPixelsY: -40  // added a negative value to move it up a bit (default 0)
    },
    onSuccess, // optional
    onError    // optional
  );
}

function hide() {
  // this function takes an optional success callback, but you can do without just as well
  window.plugins.toast.hide();
}

  window.plugins.toast.showWithOptions({
      message: 'My message',
      // More config here...
  },
      //Success callback
      function(args) {
          console.log(args.event);
          //This will print 'hide'
      }, 
      function(error) {
          console.error('toast error: ', error);
      }
  );
  
   window.plugins.toast.showWithOptions(
    {
      message: "hey there",
      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");
        }
      }
    }
  );
  
    window.plugins.toast.showWithOptions({
    message: "hey there",
    duration: "short", // 2000 ms
    position: "bottom",
    styling: {
      opacity: 0.75, // 0.0 (transparent) to 1.0 (opaque). Default 0.8
      backgroundColor: '#FF0000', // make sure you use #RRGGBB. Default #333333
      textColor: '#FFFF00', // Ditto. Default #FFFFFF
      textSize: 20.5, // Default is approx. 13.
      cornerRadius: 16, // minimum is 0 (square). iOS default 20, Android default 100
      horizontalPadding: 20, // iOS default 16, Android default 50
      verticalPadding: 16 // iOS default 12, Android default 30
    }
  });

在config.xml中我添加了这些行:

    <plugin name="cordova-plugin-x-toast" spec="^2.6.2" />
<button onclick="window.plugins.toast.showShortTop('Hello there!', function(a){console.log('toast success: ' + a)}, function(b){alert('toast error: ' + b)})">Toast showShortTop</button>
<button onclick="window.plugins.toast.showLongBottom('Hello there!', function(a){console.log('toast success: ' + a)}, function(b){alert('toast error: ' + b)})">Toast showLongBottom</button>
<button onclick="window.plugins.toast.show('Hello there!', 'long', 'center', function(a){console.log('toast success: ' + a)}, function(b){alert('toast error: ' + b)})">Toast show long center</button>
<engine name="android" spec="^7.0.0" />

我的错误在哪里? 当我按回按钮时,我可以让应用程序退出吗?

0 个答案:

没有答案