createButton and backgroundImage
I have a tableview which I am using to display contact information. I have been trying to create a mail button but I have been unable to set a backgroundImage. I have been using the following code:
var mailMe=Titanium.UI.createButton({
backgroundImage:'../img/mail.png',
right:5,
top:12,
height:32,
width:32
});
I have tried setting it from the createButton method, setting it from an event handler and changing the background, setting the backgroundImage, backgroundImageselected at creation, I tried moving the images to a different folder as explained here but have been unable to get it to work. I even tried using image instead of backgroundImage and have been unable to get it to work.
Any help would be appreciated!
2 Answers
-
Accepted Answer
I finally got it working.
My app.js opens a file in a folder called main-windows. However, as I went through the code to try to figure out what was wrong, I realized that in my code I was calling the
url:'/main-windows/main.js'
,
however, when I changed it tourl:'main-windows/main.js'
it all started working properly.Thank you Christian and Kevin for all your help!
So if you have this problem, make sure all your references are correct because although the main.js did open up, that is what prevented the backgroundImage from showing!
-
i guess you're using the android platform, if so, those properties (like backgroundImage) are only available in the constructor of the object, which means you can't change them at runtime.
my solution to this problem was creating a button while using an imageview. if you wrap this inside a custom function, you may even be able to get off/on state behaviour by using touch-event listeners
as it's true that there are quite some properties missing for the android implementation of ti-mobile, one often is able to code around them by using custom function or creating javascript classes that result in similar behaviours