0

I've looking for a way to add a menu to my app, that way when someone clicks the "menu" button they will get a custom menu that I will create. however there are no relevant posts about this. I'm looking for something similar to this:

win.addEventListner("android:menu", function(e){//DO SOMTHING});
thepoosh
  • 12,497
  • 15
  • 73
  • 132

2 Answers2

2

You cannot add an event to menu button, however, you can use the default menu.

Take a look at the doc: http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android.Menu-object

This is what I use:

// make sure window is already opened before calling this

Ti.UI.currentWindow.activity.onCreateOptionsMenu = function(e) {
    var menu = e.menu;      
    var backItem = menu.add({title: 'Back',enabled: true, itemId: '1',visible:true});
    backItem.addEventListener('click',function(){
        // do the event handling here
    });
}
Rene Pot
  • 24,681
  • 7
  • 68
  • 92
  • is there a way to change the location of the menu? I want it to be on the side instead of the bottom of the window. – thepoosh Dec 26 '11 at 13:52
  • you can't. Also see this: http://stackoverflow.com/questions/8234897/how-to-change-androids-options-menu-position – Rene Pot Dec 26 '11 at 23:35
0

When the menu button is clicked one of these two functions of the current activity is called :

  • onCreateOptionsMenu
  • onPrepareOptionsMenu

So we can do something like:

Ti.UI.currentWindow.activity.onCreateOptionsMenu = function(e) {//DO THE CUSTOM MENU };

Ti.UI.currentWindow.activity.onPrepareOptionsMenu = function(e) {//DO THE CUSTOM MENU};
youyou
  • 1