0

Hi all i want to know how to set background of layout,image view or ... to live wallpaper from java is that possible?how?? pick a live wallpaper and set that for background??we can do it with normal wallpaper with but i don't know about live wallpaper! i tried Google search for long time. i really need to know it.

this is for normal Drawable:

 File backgroundf = new File(Uri.parse("sdcar/Wallpaper_BG.jpg").getPath());
     if (backgroundf !=  null) {
        Bitmap BarbackgroundBitmap = BitmapFactory.decodeFile(backgroundf.getAbsolutePath());
        BackgroundDrawable = new BitmapDrawable(mContext.getResources(), backgroundBitmap);
        }
   mBackground.setImageDrawable(BarBackgroundDrawable);

Thanks.

Biftor
  • 148
  • 3
  • 13

1 Answers1

1

You can't do this as a drawable or a view background, but you can theme your activity to make the wallpaper or live wallpaper show through.

<style name="MyTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:colorBackgroundCacheHint">@null</item>
    <item name="android:windowShowWallpaper">true</item>
</style>

You can use any theme as the parent. Put this in your styles resource and set this theme for the activity in the manifest.

Tenfour04
  • 83,111
  • 11
  • 94
  • 154
  • thanks,i don't want it for app background theme i want,it for Android notification Panel,and also do you know how android set live Wallpaper as home screen Background?maybe that will help me.thanks – Biftor Feb 04 '14 at 01:00
  • You can't use it in the notification panel. You can at best theme your notification with different text colors and fonts: http://stackoverflow.com/q/4867338/506796 You have to use WallpaperManager to tell the system to change the live wallpaper. Prior to API 16, you can only open the system's Live Wallpaper Chooser app, but after API 16 you can directly open the preview screen for a specific live wallpaper. But you can never apply a live wallpaper directly. The user must always confirm to start a live wallpaper by pressing the Set button on the preview screen. – Tenfour04 Feb 04 '14 at 03:06
  • Info here: http://developer.android.com/reference/android/app/WallpaperManager.html – Tenfour04 Feb 04 '14 at 03:07
  • If you look at the source code of Android Wear, this is exactly how it works the new Home Launcher. The Watch Face is a Wallpaper Service, specialized class. The Home Launcher is an empty Activity with a transparent background. – Raffaeu Jun 09 '15 at 20:52