Help with Button Color on Toolbar

You must Login before you can answer or comment on any questions.

I am trying to create a custom toolbar at the TOP of my iPad app. I'm doing the following and want to use the black opaque style and color for the toolbar. When I run this code, I don't get the "pushed" look when I push on the button with these settings. I can't seem to find the right combination. Anyone?

var mapButton = Titanium.UI.createButton({
    title: "Map",
    width: 50,
    style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
})
 
mapButton.addEventListener("click", function() {
    alert('Click');
});
 
 
var helpButton = Titanium.UI.createButton({
    title: "Help",
    width: 50,
    style:Titanium.UI.iPhone.SystemButtonStyle.BAR
})
var toolbar1 = Ti.UI.createToolbar({
    top: 0,
    height: 40,
    barColor:'black',
    title:'iMap 5.0',
     items: [ 
     mapButton,
     Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FIXED_SPACE, width:35 }),
     helpButton,
     Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FIXED_SPACE, width:190 }),
     mainTitleLabel,
     Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE}), 
     Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.ACTION}),
     Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE})
            ]
    }); // end toolbar1
 
win1.add( toolbar1);

7 Answers

Accepted Answer

Try to set the barcolor to #222. It will make the push effect more visible.

Use a buttonBar instead, wit one label. It will allow you to play with the background color

var mapButton = Titanium.UI.createButton({
    labels: ["Map"],
    backgroundColor:'#a00',
    style:Titanium.UI.iPhone.SystemButtonStyle.BAR
});
Is this what u need or I'm understanding wrong ?

I am trying to do a custom bar at the TOP of my app that looks like this: http://www.imap4you.com/images/grab.tiff

— answered 2 years ago by Stephen Flournoy
answer permalink
2 Comments
  • What buttons don't have the 'pushed' stage ? If is the map, try my solution with a backgroundColor = #222

    — commented 2 years ago by Dan Tamas

  • So to have multiple buttons across the top like in the link I posted, do I need to use multiple button bars so I can space them accordingly? I was using a toolbar so I could use the Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FIXED_SPACE, width:35 }) and space my buttons the way I wanted them as well as use custom image buttons. does this make sense?

    — commented 2 years ago by Stephen Flournoy

Your approach is ok. It seems I don't understand your issue. Try to explain once more.

— answered 2 years ago by Dan Tamas
answer permalink
1 Comment
  • I'll paste the whole code. I put in your code from above. What happens is the iPhone system buttons glow when pushed fine, the Help and Map buttons are static and don't have a "pushed" state or look using this color scheme.

    // this sets the background color of the master UIView (when there are no windows/tab groups on it)
    Titanium.UI.setBackgroundColor('#000');
     
    // create tab group
     
    var tabGroup = Titanium.UI.createTabGroup();
     
    //
    // create base UI tab and root window, hide the Nav Bar here so we can put in a custom bar
    //
     
    var win1 = Titanium.UI.createWindow({  
        title:'iMap 5',
        backgroundColor:'#fff',
        //barColor:'transparent',
        navBarHidden:true
    });
     
     
    var tab1 = Titanium.UI.createTab({  
        icon:'KS_nav_views.png',
        title:'Map View',
        window:win1
    });
     
    var label1 = Titanium.UI.createLabel({
        color:'#999',
        text:'I am Window 1',
        font:{fontSize:20,fontFamily:'Helvetica Neue'},
        textAlign:'center',
        width:'auto'
    });
     
     
     
    //
    // create controls tab and root window
    //
    var win2 = Titanium.UI.createWindow({  
        title:'List View',
        backgroundColor:'#fff'
    });
    var tab2 = Titanium.UI.createTab({  
        icon:'KS_nav_ui.png',
        title:'List View',
        window:win2
    });
     
    var label2 = Titanium.UI.createLabel({
        color:'#999',
        text:'I am Window 2',
        font:{fontSize:20,fontFamily:'Helvetica Neue'},
        textAlign:'center',
        width:'auto'
    });
     
    win2.add(label2);
     
    var win3 = Titanium.UI.createWindow({  
        title:'Travel Manager',
        backgroundColor:'#fff'
    });
    var tab3 = Titanium.UI.createTab({  
        icon:'KS_nav_ui.png',
        title:'Trip Manager',
        window:win3
    });
     
    var label3 = Titanium.UI.createLabel({
        color:'#999',
        text:'I am Window 3',
        font:{fontSize:20,fontFamily:'Helvetica Neue'},
        textAlign:'center',
        width:'auto'
    });
     
    win3.add(label3);
     
     
    var win4 = Titanium.UI.createWindow({  
        title:'Track Trucks',
        backgroundColor:'#fff'
    });
    var tab4 = Titanium.UI.createTab({  
        icon:'KS_nav_ui.png',
        title:'Track Trucks',
        window:win4
    });
     
    var label4 = Titanium.UI.createLabel({
        color:'#999',
        text:'I am Window 4',
        font:{fontSize:20,fontFamily:'Helvetica Neue'},
        textAlign:'center',
        width:'auto'
    });
     
    win2.add(label4);
     
     
    //Let's create the custom NavBar (toolbar)
     
     
    var mainTitleLabel = Titanium.UI.createLabel({
        color:'white',
        text:'Imap 5.0',
        textAlign:'center',
        width:'auto'
    });
     
     
     
     
     
     
     
    var helpButton = Titanium.UI.createButton({
        title: "Help",
        width: 70,
        backgroundColor:'Red',
        style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
     
    })
     
    var mapButton = Titanium.UI.createButton({
        labels: ["Map"],
        backgroundColor:'#a00',
        style:Titanium.UI.iPhone.SystemButtonStyle.BAR
    })
     
    mapButton.addEventListener("click", function() {
        alert('Click');
    });
     
     
    var toolbar1 = Ti.UI.createToolbar({
        top: 0,
        height: 40,
        barColor:'black',
        title:'iMap 5.0',
         items: [ 
         mapButton,
         Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FIXED_SPACE, width:35 }),
         helpButton,
         Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FIXED_SPACE, width:190 }),
         mainTitleLabel,
         Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE}), 
         Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.REFRESH}),
         Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.INFO_LIGHT}),
         Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FLEXIBLE_SPACE})
                ]
        }); // end toolbar1
     
     
     
    win1.add( toolbar1);
     
    //
    //  add tabs
    //
    tabGroup.addTab(tab1);  
    tabGroup.addTab(tab2);  
    tabGroup.addTab(tab3);
    tabGroup.addTab(tab4);
     
     
    // open tab group
    tabGroup.open();

    — commented 2 years ago by Stephen Flournoy

They are 2 different type of buttons, this is why some are glowing and some not. Remove the style from the map and help button and see if it's what you need.

Dan, BTW, thanks for the patience and help here...I don't want to wear out my welcome with too many newbie questions.

So, when I remove the styles, I get the "glow" effect, but lose the button outline. I need the user to know that it's a button. As a side note, if I set the bar color to blue rather than black I get the "push" effect that I'm looking for; which is strange.

Do you think it would be an easier solution to just use an image view's instead?

Dan, looks like that and setting the SystemButtonStyle to BORDERED does the trick. Here's the code for anyone else trying the same. Thanks DAN!

var mainTitleLabel = Titanium.UI.createLabel({
                color:'white',
                text:'iMap 5.0',
                textAlign:'center',
                width:'auto',
                font: { fontSize:20, fontWeight: 'bold'}
                });//end mainTitleLabel
 
            var mapButton = Titanium.UI.createButton({
                title:"Map",
                width:56,
                style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
            })
 
 
            var helpButton = Titanium.UI.createButton({
                title: "Help",
                width: 56,
                style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED
 
            })
            var settingsButton = Titanium.UI.createButton({
                backgroundImage:"gear.png",
                width:20,
                height:20,
                style:Titanium.UI.iPhone.SystemButtonStyle.PLAIN
            })
 
 
 
            //test code
 
            var flexSpace = Titanium.UI.createButton({ systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE });
 
            var refreshButton = Titanium.UI.createButton({systemButton:Titanium.UI.iPhone.SystemButton.REFRESH});
 
            var infoButton = Titanium.UI.createButton({systemButton:Titanium.UI.iPhone.SystemButton.INFO_LIGHT});
 
            // Ti.UI.createButton({systemButton: Ti.UI.iPhone.SystemButton.FIXED_SPACE, width:140 }),
 
            var toolbar2 = Titanium.UI.createToolbar({
                items:[mapButton, flexSpace, helpButton, flexSpace, mainTitleLabel, flexSpace, settingsButton, flexSpace, refreshButton, flexSpace, infoButton ],
                top:0,
                borderTop:true,
                borderBottom:true,
            //   barColor:'#336699'
                barColor:'#222'
            });
 
            win1.add(toolbar2);

Your Answer

Think you can help? Login to answer this question!