BitmapDrawable deprecated alternative
Do this instead:
return new BitmapDrawable(context.getResources(), canvasBitmap);
Android - new BitmapDrawable deprecated; alternative Bitmap.createBitmap has to have w/h 0
Ok, instead of
myPopupWindow.setBackgroundDrawable(new BitmapDrawable());
OR
myPopupWindow.setBackgroundDrawable(new BitmapDrawable(
getApplicationContext().getResources(),
Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
));
I just use a background-color (new ColorDrawable(android.graphics.Color color)
) that I want to set to the PopupWindow. So for example, one of my PopupWindows just had a few Images without margins in between them, so I used a Transparent background for it:
myPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
And for another one I wanted to use a white background anyway, so I've used:
myPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
The constructor BitmapDrawable() is deprecated fix
Currently your class has the default constructor MyDrawable() that calls BitmapDrawable(), which is deprecated!
Add a constructor with two arguments (Resources and Bitmap) to your class and call the super constructor:
BitmapDrawable(context.getResources(), canvasBitmap);
this should fix your problem
BitmapDrawable() method deprecated
popupMessage.setBackgroundDrawable(null)
will clear the background.
From the documentation:
Change the background drawable for this popup window. The background
can be set to null.
Custom PopupWindow with BitmapDrawable deprecated method
if want to clean the background, as stated in your comment
//Clear the default translucent background
you can use
popup.setBackgroundDrawable(null);
How to use BitmapDrawable's constructor/ Making a temporary load image?
If you want to show a bitmap instead of a solid colour, extend from BitmapDrawable:
static class DownloadedDrawable extends BitmapDrawable {
private final WeakReference<BitmapDownloaderTask> bitmapDownloaderTaskReference;
public DownloadedDrawable(Resources resources, Bitmap bitmap, BitmapDownloaderTask bitmapDownloaderTask) {
super(resources, bitmap);
bitmapDownloaderTaskReference =
new WeakReference<BitmapDownloaderTask>(bitmapDownloaderTask);
}
public BitmapDownloaderTask getBitmapDownloaderTask() {
return bitmapDownloaderTaskReference.get();
}
}
To use it:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.your_drawable);
DownloadedDrawable draw = new DownloadedDrawable(getResources(), bitmap, yourBitmapDownloaderTask);
yourImageView.setImageDrawable(draw);
Related Topics
Android Active Link of Url in Textview
Camera Preview Is in Portrait Mode But Image Captured Is Rotated
Android Build Gradle Is Too Slow (Dependency Resolution)
How to Set Status Bar Background as Gradient Color or a Drawable in Android
Why Is Fusedlocationapi.Getlastlocation Null
Showing The Current Selection in a Listview
Calling a Activity Method from Broadcastreceiver in Android
Multiple Notifications to The Same Activity
How to Enable Night Mode Programmatically
How to Remove Black Background Between Start New Activity During Slide_Left Animation
Android: Wait on User Input from Dialog
Syncadapter Without a Contentprovider
Change Navigation Bar Icon Color on Android
How to Repeat Notification Daily on Specific Time in Android Through Background Service
How to Get Background Color from Current Theme Programmatically
Android Ble Connection Time Interval
Install_Failed_Cpu_Abi_Incompatible on Device Using Intellij