3

I'm using this code to change the wallpaper of the android home

WallpaperManager wm = WallpaperManager.getInstance(this);
wm.setBitmap(myBitmap);

I would like to set the background to a drawable. Is this possible?

Jack Love
  • 726
  • 3
  • 11
  • 17
  • Not really AFAIK. Even setResource() requires a JPEG/PNG resource. Your only option, I suppose, would be a live wallpaper. – EboMike Oct 21 '10 at 21:34
  • possible duplicate of [Android: how to convert a Drawable to Bitmap](http://stackoverflow.com/questions/3035692/android-how-to-convert-a-drawable-to-bitmap) – EboMike Oct 21 '10 at 21:37

1 Answers1

5

You'll first have to convert the Drawable to a Bitmap. How to do this I found here. You'll need to use the BitmapFactory class, specifically the decodeResource() method.

Simply pass in the Resources and the Resource ID as parameters, like so:

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.my_drawable);
wm.setBitmap(bmp);
Community
  • 1
  • 1
Kevin Coppock
  • 133,643
  • 45
  • 263
  • 274