0
我試圖在android上更換壁紙。但它突出顯示了圖像的一部分。然而,如果我鎖定手機,鎖定屏幕會顯示完美縮放的圖像,但只有在應用程序正在運行時,退出時鎖定屏幕纔會顯示與背景相同的圖像?在android上更換壁紙
help!?
WallpaperManager wallpaperManager = WallpaperManager.getInstance(getApplicationContext());
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
Bitmap original = BitmapFactory.decodeResource(getResources(), R.drawable.day_cloudy);
Bitmap resized = Bitmap.createScaledBitmap(original, width, height, true);
try {
wallpaperManager.clear();
wallpaperManager.setWallpaperOffsetSteps(1, 1);
wallpaperManager.suggestDesiredDimensions(resized.getWidth(), resized.getHeight());
wallpaperManager.setBitmap(resized);
Toast.makeText(this, "Wallpaper Set", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}