弃用 Drawable.getOpacity()

问题描述

我收到 Drawable.getopacity() 的弃用警告。

...\progressbar\MaterialProgressDrawable.java:304: warning: [deprecation] getopacity() in Drawable has been deprecated
    public int getopacity() {
               ^
1 warning

这个类 (MaterialProgressDrawable) 扩展了 Drawable 并实现了 Animatable。由于 getopacity() 在父类 (@Deprecated public abstract @PixelFormat.Opacity int getopacity();) 中是抽象的,因此我也无法完全删除方法。出路是什么?

解决方法

出路是什么?

好吧,由于 javadoc 暗示不再使用该方法,因此一种解决方案是按如下方式实现它:

@SuppressWarnings("deprecation")
public int getOpacity() {
    throw new UnsupportedOperationException("getOpacity is deprecated");
}