Android ApiDemos示例解析(15):App->Activity->SetWallpaper

SetWallpaper介紹如何在Android獲取當前Wallpaper,對Wallpaper做些修改,然後用修改後的圖像重新設置Wallpaper。

WallpaperManager用來管理Android的Wallpaper。下面代碼通過WallpaperManager來取得當前Wallpaper然後顯示在屏幕Layout的imageView上。

[java] 
final WallpaperManager wallpaperManager 
 = WallpaperManager.getInstance(this); 
final Drawable wallpaperDrawable 
 = wallpaperManager.getDrawable(); 
final ImageView imageView 
 = (ImageView) findViewById(R.id.imageview); 
imageView.setDrawingCacheEnabled(true); 
imageView.setImageDrawable(wallpaperDrawable); 
final WallpaperManager wallpaperManager
 = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable
 = wallpaperManager.getDrawable();
final ImageView imageView
 = (ImageView) findViewById(R.id.imageview);
imageView.setDrawingCacheEnabled(true);
imageView.setImageDrawable(wallpaperDrawable);
重新設置Wallpaper,也是通過WallpaperManager。

[java] 
wallpaperManager.setBitmap(imageView.getDrawingCache()); 
wallpaperManager.setBitmap(imageView.getDrawingCache());

 
作者:mapdigit

發佈留言