Titanium Community Questions & Answer Archive

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

BackgroundImage for createButton on Android

I know that backgroundImage does not work on android and that we are supposed to use image instead (Would be nice if we had the backgroundSelectedImage and backgroundImage for android though). It seems when using this method however that the touchable surface area decreases. Is there a better method that I should be using for using an image as a button in android. Thanks in advance for any replies.

— asked April 21st 2010 by Joseph Burger
  • android
  • buttons
0 Comments

3 Answers

  • Hey Joseph

    backgroundImage for Button should be working now in HEAD.. I recently pushed some fixes surrounding this. You should be aware, however, that android skews your image and tries to make it "look" like a button, so it may not be exactly what you want. We have a built-in 9-patch parser that can take an Android-style 9-patch PNG and automatically stretch for use as a button's background image. You might check out the doc on 9-patch PNGs here:
    http://developer.android.com/guide/developing/tools/draw9patch.html

    — answered April 22nd 2010 by Marshall Culpepper
    permalink
    5 Comments
    • Marshall, would you mind confirming whether backgroundImage, backgroundSelectedImage and backgroundDisabledImage currently respond to the enabled=true/false property under android? I cannot seem to get it to work.
      Thanks in advance
      Hal

      — commented June 23rd 2010 by Paul Dowsett
    • To answer my previous post, these properties now work in the latest build of 1.4

      — commented November 1st 2010 by Paul Dowsett
    • I have only tested it with button view but 9patch works great on android for the properties backgroundImage, backgroundDisabledImage and backgroundSelectedImage

      — commented November 1st 2010 by Paul Dowsett
    • in case anyone is interested, there is a iOS feature request for 9-patch here. Go add a +1 if you need it :)

      — commented November 1st 2010 by Paul Dowsett
    • I have tried many different approaches to getting a png image to display both on a background image and on a button in the Android virtual device (AVD).

      I've tried moving the image into many different places. I've tried referencing the image in various ways. I've tried converting the image to jpeg. I've tried using "backgroundImage:" and "image:".

      Here is the code for the non working background image:

      var crustTitleView = Ti.UI.createView({  
                  width:328,  
                  height:58,  
                  backgroundImage:'../images/crustHeaderBg.png',  
                  top:100,  
                  left:6,  
                  opacity:0  
          });
      

      Here is the code for the non working button:

      ar next = Ti.UI.createButton({ 
                  title:'Test Button', 
                  width:137,  
                  height:75,  
                  backgroundImage:'../images/toppings_next.png',  
                  top:385,  
                  opacity:0  
          });
      if (Ti.Platform.osname == 'android')  
          {  
              next.image = '../images/toppings_next.png';  
          }
      

      Any help would be greatly appreciated!

      — commented September 28th 2011 by John Dietrich
  • Sorry for the double post. Got the red error message and two messages were submitted.

    — answered April 21st 2010 by Joseph Burger
    permalink
    0 Comments
  • Sorry for the double post. Got the red error message and two messages were submitted.

    — answered April 21st 2010 by Joseph Burger
    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.