Onsen ui:Disable device backbutton in android didnt work

為{幸葍}努か 提交于 2019-12-25 07:03:52

问题


I am developing an android application using Cordova and Onsenui, in whic i want to disable the android back button handler. I've tried this answer ,but didnt work for me

Here is my code its placed on top of my app.js file

ons.ready(function() {
  ons.disableDeviceBackButtonHandler();

});

回答1:


Supposing that you are using <ons-navigator var="myNavigator"></ons-navigator>, have you already tried something like this?

// To disable a navigator back button handler
myNavigator.getDeviceBackButtonHandler().disable();

You should also not forget to add cordova.js reference to your index page. You don't need to paste the file, it will be generated automatically every time you deploy a Cordova app.

<script src="cordova.js"></script>

If you don't add it, it will not be possible to manipulate the BackButton behavior.

Default behavior:

  • Main page: closes the app.
  • Other pages: goes back.

Disabling the handler, the app will be closed every time you press the button, regardless the page.



来源:https://stackoverflow.com/questions/31869577/onsen-uidisable-device-backbutton-in-android-didnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!