NappDrawer
NappDrawer copied to clipboard
Problem about adding menu icons into actionbar
Good day Viezel :) Just wondering is it possible to add menu icons to the action bar (right hand side menu)? I was able to setTitle and set logo button successfully, just having trouble while adding menu button to the actionbar. Could you help me out? Thanks a lot!
According to the code section of 'Action Bar - REAL example'
var actionBar; // Action Bar - REAL example drawer.addEventListener('open', onNavDrawerWinOpen); function onNavDrawerWinOpen(evt) { this.removeEventListener('open', onNavDrawerWinOpen); if(this.getActivity()) { // need to explicitly use getXYZ methods actionBar = this.getActivity().getActionBar();
if (actionBar) {
// Now we can do stuff to the actionbar
actionBar.setTitle('NappDrawer Example');
// show an angle bracket next to the home icon,
// indicating to users that the home icon is tappable
actionBar.setDisplayHomeAsUp(true);
// toggle the left window when the home icon is selected
actionBar.setOnHomeIconItemSelected(function() {
drawer.toggleLeftWindow();
});
this.getActivity().onCreateOptionsMenu = function(e) {
console.log('onCreateOptionsMenu');
var menu = e.menu;
var btn1 = menu.add({
title : "btn1",
itemId : 1
});
btn1.setIcon("images/addBtn.png");
var btn2 = menu.add({
title : "btn2",
itemId : 2
});
btn2.setIcon("images/minBtn.png");
};
this.getActivity().onPrepareOptionsMenu = function(e) {
console.log('onPrepareOptionsMenu');
var menu = e.menu;
menu.findItem(1).setVisible(true);
menu.findItem(2).setVisible(true);
};
this.getActivity().invalidateOptionsMenu();
}
}
}
I also have this problem. Seems that the code posted by BitterSymphony does not work and i didn't fund a way to add menu buttons to the action bar
I have this problem too.A onCreateOptionsMenu method never called on startup,but when you pressed menu button you get menu item.Weird problem.
activity.onCreateOptionsMenu = function(e){ e.menu.clear(); editButton = e.menu.add({ itemId: 1, title: "Edit", icon : '/edit.png', showAsAction : Ti.Android.SHOW_AS_ACTION_ALWAYS }); addButton = e.menu.add({ itemId: 2, title: "Edit", icon : '/camera.png', showAsAction : Ti.Android.SHOW_AS_ACTION_ALWAYS }); };