Titanium Community Questions & Answer Archive

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

Button backgroundColor ignored

Hi,

I have a standard button created with the following code:

exampleButton = Ti.UI.createButton({
color:Ti.App.Properties.getString('default_text_color'),
font:{fontSize:16,fontWeight:'bold'},
title:"Test",
backgroundColor:'#336699',
borderRadius:10,
width: 120,
height: 30,
top:250
});

The background color of the button does not change, it stays white. Any ideas?

Thanks,
Bruce

— asked March 10th 2010 by Bruce McTigue
  • backgroundcolor
  • button
0 Comments

18 Answers

  • I found this thread b/c i was having the same problem. Don't know if everyone has found their own answer by now but setting the background image to 'none' fixes the white background problem.

    This is my button code that works for me…hope it helps!

    var saveNewUser = Titanium.UI.createButton({
        borderRadius: 2,
        height: 25,
        right: 10,
        title: 'Add user',
        top: 175,
        width: 100,
        backgroundColor: '#000000',
        borderColor: '#1c1d1c',
        color: '#ffffff',
        borderWidth: '2',
        backgroundImage: 'none'
    });
    
    — answered May 10th 2010 by Kelly Redd
    permalink
    5 Comments
    • thx a lot. 1 year and the bug still there.

      — commented August 28th 2011 by ben roe
    • Great solution!Thanks,

      — commented September 6th 2011 by Patty Mapes
    • Thanks!! it's a great solution.

      — commented November 29th 2011 by Titanium Developer
    • Thanks - very useful!

      — commented December 7th 2011 by Dan Smart
    • Well the bug still remains. Thank you for sharing

      — commented December 2nd 2013 by Christos Gkrezios
  • The following worked for me. i think the none has to be in capital letters (NONE)

    var comboRadio = Ti.UI.createButton ({
                color: '#9CC1E6',
                title:'Combination',
                borderRadius: 15,
                borderWidth: 1,
                borderColor: '#9CC1E6',
                backgroundColor: 'white',
                backgroundImage: 'NONE',
                width: 280,
                font: {
                    fontSize: 15,
                    fontWeight: 'bold'
                },
                height: 30,
                top:140,
                value:false
    });
    
    — answered April 2nd 2011 by fahad kashem
    permalink
    0 Comments
  • Workaround: You can use the ButtonBar. The important thing to remember, is to specify the style!

    Example:

      var newButton = Titanium.UI.createButtonBar({
        labels:[{title:'Some title', width:100}],
        style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
        backgroundColor:'#f4a010',
        top:5,
        left:5,
        height:40,
        width:'auto'
      });
    
    — answered November 22nd 2010 by John Doktor
    permalink
    0 Comments
  • All buttons are white for me as well

    var searchBtn = Titanium.UI.createButton({
        backgroundColor: '#666',
        title:'Search',
        color: '#ccc',
        top:100,
        left:30,
        height:53,
        width:250
    });
    
    — answered March 16th 2010 by Mark Stocks
    permalink
    0 Comments
  • The following worked for me. i think the none has to be in capital letters (NONE)

    var comboRadio = Ti.UI.createButton ({
                color: '#9CC1E6',
                title:'Combination',
                borderRadius: 15,
                borderWidth: 1,
                borderColor: '#9CC1E6',
                backgroundColor: 'white',
                backgroundImage: 'NONE',
                width: 280,
                font: {
                    fontSize: 15,
                    fontWeight: 'bold'
                },
                height: 30,
                top:140,
                value:false
    });
    
    — answered April 2nd 2011 by fahad kashem
    permalink
    0 Comments
  • I can't believe this problem still exists. How disappointing to have a fully functional app in Android, only to fire it up on iPhone for the first time, and it looks like complete crap. Finally found this issue, and the backgroundImage: 'NONE' fix mercifully makes it respect your backgroundColor settings.

    However, in my case, although the bg changed, the text wasn't visible anywhere, even when set to white on a black bg. The fix turns out to be specifying an explicit height, then the text shows up. Hopefully this will help someone else down the road who might have the same issue.

    — answered October 14th 2011 by Tony Higham
    permalink
    0 Comments
  • Bug filed:

    https://appcelerator.lighthouseapp.com/projects/32238-titanium-mobile/tickets/1727-button-backgroundcolor-does-not-work

    If you are having this issue as well, please follow this ticket so that it gets fixed.

    — answered September 3rd 2010 by Robby Dermody
    permalink
    1 Comment
    • Appcelerator are now using JIRA link here.

      http://jira.appcelerator.org/browse/TIMOB-1727

      Check the comments and compare them with the Ti UI Button docs…

      Basically appcelerator are saying this as per Apples design and you have to use background image to customise a button…

      The bug has been marked as invalid.

      — commented October 19th 2011 by Jeff Antram
  • This works

    Ti.UI.createButton({
        backgroundColor: '#FF0000',
        backgroundImage: 'none',
    });
    
    — answered April 24th 2012 by Dallas Clark
    permalink
    0 Comments
  • Hi,

    Have you checked to see if Ti.App.Properties.getString('default_text_color') actually returns something?

    The whole Properties thing is a mystery to me. I'd like to see some documentation on it.

    — answered March 10th 2010 by Bill Dawson
    permalink
    0 Comments
  • I agree that the backgroundColor doesn't seem to be working on buttons.

    — answered March 11th 2010 by Rob Edgell
    permalink
    0 Comments
  • I'm finding backgroundColor working with no issues - I've got a button set to #fff so that it has no apparent background, and it works, and 6-digit colours are also fine. Images, now, they're a problem. :-)

    — answered March 12th 2010 by John Pettigrew
    permalink
    0 Comments
  • John-

    Try changing the background to another color besides #fff. This is the default color that we are all seeing with this issue.

    — answered March 16th 2010 by Mark Stocks
    permalink
    0 Comments
  • If you set the property 'borderRadius:0' on the button, you will notice that the background colour is being applied to a rectangle behind the button.

    — answered March 18th 2010 by Richard Fyffe
    permalink
    0 Comments
  • I second that, not working as expected.

    — answered March 26th 2010 by Maurice Faber
    permalink
    0 Comments
  • Is there any news on this? I am almost ready with my app and hope to release next week, if only this would be solved :|

    — answered March 30th 2010 by Maurice Faber
    permalink
    0 Comments
  • Ya, I can't get the background image to work too :-(

    — answered April 14th 2010 by Peter Lum
    permalink
    0 Comments
  • I'm finding that backgroundColor is broken in 1.4.0 as well (even using some of the examples here).

    As a workaround, you could make a ButtonBar with just one entry to it:

    var myButton = Ti.UI.createButtonBar({
        labels:['ButtonText'],
        backgroundColor: 'green'
    });
    

    Then just hook into the click event like normal (buttonbars ship an index property over that tells you which entry in the bar was clicked, but since we just have one it doesn't matter).

    — answered August 20th 2010 by Robby Dermody
    permalink
    0 Comments
  • The following worked for me. i think the none has to be in capital letters (NONE)

    var comboRadio = Ti.UI.createButton ({
                color: '#9CC1E6',
                title:'Combination',
                borderRadius: 15,
                borderWidth: 1,
                borderColor: '#9CC1E6',
                backgroundColor: 'white',
                backgroundImage: 'NONE',
                width: 280,
                font: {
                    fontSize: 15,
                    fontWeight: 'bold'
                },
                height: 30,
                top:140,
                value:false
    });
    
    — answered April 2nd 2011 by fahad kashem
    permalink
    0 Comments
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.