0

am developing android app in titanium appcelerator. Now my problem is that i have to add action bar in my app and put two buttons in left and right side of it

but i cant successfully implement the action bar

i have done following to make show action bar but its just crashes ma application,

    var win = Ti.UI.createWindow({
        title: _args.title,
        backgroundColor:'black',
        navBarHidden: false,
        containingTab: _args.containingTab,
        //tabGroup: _args.tabGroup,
        barImage:rootPath+'/Components/top_bg.jpg'
    });


var actionBar;
win.addEventListener("open", function() {
    if (Ti.Platform.osname === "android") {
        if (! win.activity) {
            Ti.API.error("Can't access action bar on a lightweight window.");
            alert("NOT ACTIVITY");
        } else {
            actionBar = win.activity.actionBar;
            if (actionBar) {
                alert("ACTIVITY");
                actionBar.backgroundImage = "/images/bg_top.png";
                actionBar.title = "New Title";
                actionBar.onHomeIconItemSelected = function() {
                    Ti.API.info("Home icon clicked!");
                };
            }
        }
    }
});

can anyone please guide me where am doing mistake? or is there anything else that i have to follow.

BhavikKama
  • 8,566
  • 12
  • 94
  • 164

2 Answers2

4

try wrapping it in onCreateOptionsMenu

   win.activity.onCreateOptionsMenu = function(e) {
        actionBar = win.activity.actionBar;
        if (actionBar) {
            alert("ACTIVITY");
            actionBar.backgroundImage = "/images/bg_top.png";
            actionBar.title = "New Title";
            actionBar.onHomeIconItemSelected = function() {
                Ti.API.info("Home icon clicked!");
            };
        } else {
            alert('missing action bar');
        }
     });
Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
1

I had the same problem and it took some time to find out which code I have to put in the tiapp.xml

<uses-sdk android:maxSdkVersion="18" 
            android:minSdkVersion="11" android:targetSdkVersion="18"/>

Put this in the manifest element and it should work. Notice that the actionbar only works in android api 11 and higher.

Sven Keinath
  • 371
  • 3
  • 13