Search code examples
titanium-mobileappcelerator-mobiletitanium-alloy

Appcelerator Alloy Click Event for Status Bar Icon


Is it possible to create a click event using the status bar icon enter image description here


Solution

  • You need to add a callback to the onHomeIconItemSelected property. Say you have a Tabgroup with a "tabGroup" id, it would be something like:

    $.tabGroup.addEventListener('open', function(e) {
        var activity = $.tabGroup.activity;
        // Avoid older APIs executing this code
        if( Ti.Platform.Android.API_LEVEL >= 11 ) {
            activity.actionBar.onHomeIconItemSelected = function() {
                alert("Home icon clicked!");
            };  
        }
    }
    

    For a more complete and detailed explanation, you could refer to https://github.com/websterj/Alloy2TabbedAndroidUI which is a good demonstration of an app using the Action Bar in Titanium.