我使用Glide
从URL
加载图像并将其设置为墙纸,但是当将过渡应用于glide
时,图像随过渡加载,但当图像设置为墙纸使应用程序崩溃(加载时不进行过渡,一切正常)
java.lang.ClassCastException: android.graphics.drawable.TransitionDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
这是我要加载的代码
Glide.with(this).asBitmap()
.load(imageUrl)
.apply(new RequestOptions().centerCrop())
.transition(BitmapTransitionOptions.withCrossFade())
.into(image);
并用于应用壁纸
Bitmap bitmapImg = ((BitmapDrawable) image.getDrawable().getCurrent()).getBitmap();
WallpaperManager wallManager = WallpaperManager.getInstance(getApplicationContext());
try {
wallManager.clear();
wallManager.setBitmap(bitmapImg);
Snackbar.make(view, "Wallpaper set successfully", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
} catch (IOException ex) {
Toast.makeText(fullscreen.this, "Error!", Toast.LENGTH_SHORT).show();
}