Reputation: 12587
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});
Upvotes: 0
Views: 2555
Reputation: 1
When the menu button is clicked one of these two functions of the current activity is called :
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};
Upvotes: 0
Reputation: 24815
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
});
}
Upvotes: 2