Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Create a toolbar with buttons

I am trying to create a simple application with just a webview at the top and a toolbar at the bottom. I can add both the webview and toolbar but can not add buttons into the toolbar. I would appreciate if anybody can help me?

`var webView = Titanium.UI.createWebView({
url:'http://google.com',
width:320,
height:416,
left:0,
top:0
});

//var aSimpleBarButton = Titanium.UI.createBarButton({
//});
//
//var aSimpleButton = Titanium.UI.createButton({
//
//});

var webToolbar = Titanium.UI.createToolbar({
center:{
x:0,
y:440
}
});

//webToolbar.add(aSimpleButton);

//webToolbar.add(aSimpleButton);

win1.add(webToolbar);

win1.add(webView);

win1.open();`

I try to add either barbutton or button into the toolbar but the iphone simulator just crashed

— asked November 10th 2010 by Khang Vo
  • button
  • iphone
  • toolbar
0 Comments

1 Answer

  • when creating a toolbar you add the buttons in an array, See excerpt from KitchenSInk windows_toolbar.js

        var b = Titanium.UI.createButton({
            title:'Button',
            style:Titanium.UI.iPhone.SystemButtonStyle.DONE        
        });
        var flexSpace = Titanium.UI.createButton({
            systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
        });
        b.addEventListener('click', function() {
            Ti.API.info('Clicked right button!');
        });
        win.setToolbar([flexSpace,b]);
    
    — answered November 10th 2010 by Aaron Saunders
    permalink
    2 Comments
    • Thanks for the answer, how can you get the win variable? I tried your solution but doesn't work

      — commented November 12th 2010 by Khang Vo
    • var win = Ti.UI.currentWindow;

      — commented November 30th 2010 by Justin Toth
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.