viezel / NappDrawer

A side drawer navigation container view controller for Appcelerator Titanium.
MIT License
248 stars 128 forks source link

Problem about adding menu icons into actionbar #142

Open BitterSymphony opened 9 years ago

BitterSymphony commented 9 years ago

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();
    }
}    

}

andrea-lascola commented 9 years ago

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

ghost commented 8 years ago

I have this problem too.A onCreateOptionsMenu method never called on startup,but when you pressed menu button you get menu item.Weird problem.

bahinapster commented 8 years ago

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 }); };