Android经验分享

检测视图是否透明

2019-12-06  本文已影响0人  没头脑和挺高兴

有时候需要检测视图是否同名,可以使用下面的方法.

private static boolean viewIsOpaque(View v) {
if (v.isOpaque()) {
return true;
}

    // View#isOpaque didn't take all valid opaque scrollbar modes into account
    // before API 18 (JB-MR2). On newer devices rely solely on isOpaque above and return false
    // here. On older devices, check the view's background drawable directly as a fallback.
    if (Build.VERSION.SDK_INT >= 18) {
        return false;
    }

    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }
    return false;
}
上一篇下一篇

猜你喜欢

热点阅读