0

I have xml shape file

<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:angle="90"
    android:startColor="#420012"
    android:centerColor="#670000"
    android:endColor="#420012"
    android:type="linear" />
<stroke
    android:width="1px"
    android:color="#560000" />
</shape>

How to set it as wallpaper? Is it possible? I need an explanation.

If I execute this, device's default wallpaper to be set.

WallpaperManager wm=WallpaperManager.getInstance(this);
wm.SetResource(R.drawable.bg);
Marsh K
  • 151
  • 1
  • 2
  • 9

2 Answers2

1

Hope you have included the below permission in your Manifest file:-

android.permission.SET_WALLPAPER

And the xml file (bg.xml) that you have created needs to be placed in drawable folder under res folder which you can set as your wallpaper as per your code:-

WallpaperManager wm=WallpaperManager.getInstance(this);
wm.setResource(R.drawable.bg);
Karthik
  • 184
  • 1
  • 3
  • 11
0

Live wallpaper do drawing using Surface and Canvas APIs. What you can do is inflating some Views from XML and draw() them to a Canvas. But its troublesome. Lengthy and not suggested.

Zahan Safallwa
  • 3,880
  • 2
  • 25
  • 32