javascript - Disabling menu button in Android using PhoneGap - Stack Overflow

admin2025-04-19  0

I'm building my first mobile app using PhoneGap and jQuery Mobile, and I've run into a little issue.

I've been testing it on Android, both on a physical device and the emulator. As this application is very simple and has nothing much in the way of settings, I'd like to disable the Menu button.

Now, the impression I got from the PhoneGap documentation is that you need to add an event listener for the menubutton event in order to override the default behaviour, and use preventDefault to stop the default action taking place. Try as I might, I can't seem to get it to work. The code I've written for it is on JSFiddle.

Is this possible? If so, any idea where I'm going wrong?

EDIT: Should really have mentioned the version - I'm using PhoneGap 2.0.

I'm building my first mobile app using PhoneGap and jQuery Mobile, and I've run into a little issue.

I've been testing it on Android, both on a physical device and the emulator. As this application is very simple and has nothing much in the way of settings, I'd like to disable the Menu button.

Now, the impression I got from the PhoneGap documentation is that you need to add an event listener for the menubutton event in order to override the default behaviour, and use preventDefault to stop the default action taking place. Try as I might, I can't seem to get it to work. The code I've written for it is on JSFiddle.

Is this possible? If so, any idea where I'm going wrong?

EDIT: Should really have mentioned the version - I'm using PhoneGap 2.0.

Share Improve this question edited Aug 17, 2012 at 14:37 Matthew Daly asked Aug 17, 2012 at 10:06 Matthew DalyMatthew Daly 9,5162 gold badges46 silver badges86 bronze badges 7
  • Hey @mattbd that code looks right. What behaviour are you getting when you click on the menu? – Simon MacDonald Commented Aug 17, 2012 at 13:57
  • @SimonMacDonald The Settings dialogue pops up as usual. It looks like it gets called, because if I put an alert() in above e.preventDefault(), that works. Does the same on both the Android emulator and my phone, so it doesn't look like it's something device-specific, – Matthew Daly Commented Aug 17, 2012 at 14:14
  • Why are you providing a settings dialog if you don't want to see one? – Simon MacDonald Commented Aug 17, 2012 at 14:50
  • 1 I'm not providing one. As far as I can see it's there by default. It's a very simple application and I felt that the default Settings dialogue was superfluous. – Matthew Daly Commented Aug 17, 2012 at 14:59
  • 1 I've basically just used docs.phonegap./en/2.0.0/… as a starting point, and everything else has been HTML, CSS and JavaScript. I haven't touched the XML or Java files beyond that – Matthew Daly Commented Aug 17, 2012 at 22:10
 |  Show 2 more ments

1 Answer 1

Reset to default 7

I had the same problem. Seems to be a new default in PhoneGap 2.0.

In the .java file under the src folder (MainActivity.java appears to be the default file name), ment out onCreateOptionsMenu function.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745002879a279337.html

最新回复(0)