Appcelerator-Q-A-banner

createButton and backgroundImage

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

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 to url:'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

— answered 5 years ago by Christian Sigl
answer permalink
12 Comments
  • I am actually using the iPhone platform as you can see in the tags. I still haven't been able to get it to work though.

    — commented 5 years ago by Abraham Vivas

  • sorry, you are speaking about no being able to get the initial image working, or not being able to change the image afterwards?

    — commented 5 years ago by Christian Sigl

  • Neither. I can't set the initial image and I also tried by changing it afterwards and haven't been able to either. I get a blank button that turns blue when clicked.

    — commented 5 years ago by Abraham Vivas

  • Show 9 more comments

Your Answer

Think you can help? Login to answer this question!