Search code examples
androidbackgroundwallpaper

Set app background to be the same as home screen wallpaper


I want to set my app's background to be the same as my home screen's wallpaper. How can I get the home screen wallpaper in activity.xml? Can I do that?


Solution

  • Use

    final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
    

    to get the current wallpaper. Then set it as your own app's background:

    LinearLayout ll = (LinearLayout) findViewById(R.id.myLinearLayout);//Substitute with your layout
    ll.setBackground(wallpaperDrawable); 
    

    All this should happen in the onCreate() if you wish to have it as the initial background.