backgroundImage problem
I'm new to Titanium and can't make buttons gain the desired background at creation time. I can change the background during events, but not initially. Anyone got any ideas?
I've got the following code to create the button:
var a1 = Titanium.UI.createButton({
title:'Hit',
backgroundColor:'#33ccff',
backgroundImage:'images/BUTT_drk_off.png',
height:40,
width:200,
top:100,
color:'#fff'
});
If I change backgroundImage
in my event listener then it works, and I can change back and forth between my images fine. It's just the initial state that doesn't seem to work for me.
Running the resultant code on the Android emulator, BTW.
4 Answers
-
Accepted Answer
For some reason,it seems you have to use 'image' when dealing with Android buttons.
var a1 = Titanium.UI.createButton({ title:'Hit', backgroundColor:'#33ccff', image:'images/BUTT_drk_off.png' });
backgroundImage appears to only work on iPhone.
-
Hmm. Actually, although I can indeed set the button image with
image
, I can't then change it in response to events! So it's one step forwards and one back! -
To clarify you are running into issues in creating the button with the desired image? If that is the case I'd recommend looking at the KitchenSink example button.js it has some nice examples like the below.
Another area to look into is if any of the events you are using to manage your button images might be firing during the load process. This could be causing issues with image when the page is loaded.
var b3 = Titanium.UI.createButton({ color:'#fff', backgroundImage:'../images/BUTT_grn_off.png', backgroundSelectedImage:'../images/BUTT_grn_on.png', backgroundDisabledImage: '../images/BUTT_drk_off.png', top:110, width:301, height:57, font:{fontSize:20,fontWeight:'bold',fontFamily:'Helvetica Neue'}, title:'Click Me' });
-
Ben,
It's not the creation but setting an image that's the problem. Indeed, I can (as I said) change the image. I just can't get a different image to appear from creation time, just the default appearance.Jacob,
It's odd but I can change the image usingbackgroundImage
on Android. Setting it withimage
does work, but of course I then need to change it withimage
also. Many thanks for this. Now to try and code so that it'll work on iPhone as well as Android.Hope this bug gets sorted soon!