我试图用android菜单按钮打开我的侧边菜单。我在互联网上找到了这个解决方案:
Ionic/Cordova menubutton event not called
但它对我不起作用。这是我的代码:
var starter = angular.module('starter', ['ionic', 'starter.controllers'])
.run(function ($ionicPlatform, $rootScope, $state, $ionicSideMenuDelegate) {
$ionicPlatform.ready(function () {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
document.addEventListener("menubutton", onMenuKeyDown, false);
function onMenuKeyDown() {
alert("some menu pops pup!! ");
// here change the view , etc...
$rootScope.$apply();
}
});
})
答案 0 :(得分:1)
你需要覆盖android方法!
这是我的代码:
$ionicPlatform.ready(function() {
navigator.app.overrideButton("menubutton", true);
document.addEventListener("menubutton", onMenuKeyDown, false);
function onMenuKeyDown() {
console.log("Menu");
}
});