构造函数BitmapDrawable()已被弃用,需要修复。

5

我有一个扩展了 BitmapDrawable 的类,代码如下:

public class MyDrawable extends BitmapDrawable {
    protected Drawable drawable;

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

而Eclipse警告我构造函数BitmapDrawable()已被弃用。一切都运行得很好,但我想修复我的类,以便不会收到此消息。

非常感谢任何帮助。

1个回答

7

目前你的类有一个默认构造函数MyDrawable(),它调用了已经过时的BitmapDrawable()!

在你的类中添加一个带有两个参数(Resources和Bitmap)的构造函数,并调用父类构造函数:

 BitmapDrawable(context.getResources(), canvasBitmap);

这应该解决您的问题。


你的回答很有帮助,虽然我还得自己想办法去实现你的建议。 :) 这是正确的做法吗?MyDrawable(Resources r, Bitmap canvasBitmap) { super(r, canvasBitmap); } - milosh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接