Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The constructor BitmapDrawable() is deprecated fix [duplicate]

I have a class that extends BitmapDrawable that looks like this:

public class MyDrawable extends BitmapDrawable {
    protected Drawable drawable;

    @Override
    public void draw(Canvas canvas) {
        if(drawable != null) {
            drawable.draw(canvas);
        }
    }
    // some other methods...
}

and Eclipse warns me that constructor BitmapDrawable() is deprecated. Everything is working just fine but I would like to fix my class so I don't get this message.

Any help is appreciated.

like image 926
milosh Avatar asked Mar 17 '23 22:03

milosh


1 Answers

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

like image 80
Michael Avatar answered Apr 02 '23 03:04

Michael