Titanium Community Questions & Answer Archive

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

How can I set a background image for the window I'm in?

I've tried the following code but I'm not sure why it doesn't work. It opens up the gallery, I choose a photo and it returns me to the gallery, but the background doesn't change.

Any thoughts?

button.addEventListener('click', function() {
  Titanium.Media.openPhotoGallery({
        success: function(event) {
            var image = event.media;

            win.backgroundImage = null;
            win.backgroundImage = image.nativePath;
        },
        cancel: function(){},
        error: function(error) {}
    });
});
— asked November 14th 2010 by Cory Dorning
  • android
  • nativepath
  • openphotogallery
1 Comment
  • There isn't much of your code to go on, Cory. Have you tried setting win.backgroundImage to point to a standard png file located in the Resources directory, to determine whether that works?

    — commented November 16th 2010 by Paul Dowsett

1 Answer

  • Replace image.nativepath with image only.
    Use below code

    button.addEventListener('click', function() {
      Titanium.Media.openPhotoGallery({
            success: function(event) {
                var image = event.media;
    
                win.backgroundImage = null;
                win.backgroundImage = image;
            },
            cancel: function(){},
            error: function(error) {}
        });
    });
    
    — answered December 31st 2012 by Dharmendra Patel
    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.