Android WindowManager背景暗化

AndroidWindowManager大约 1222 字

WindowManager.LayoutParams.FLAG_DIM_BEHIND mParams.dimAmount = 0.5f;

mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mLayoutParams = new LayoutParams();
mLayoutParams.height = LayoutParams.WRAP_CONTENT;
mLayoutParams.width = LayoutParams.MATCH_PARENT;
mLayoutParams.gravity = Gravity.BOTTOM;
mLayoutParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | LayoutParams.FLAG_DIM_BEHIND;
mLayoutParams.dimAmount = 0.5f;
mLayoutParams.format = PixelFormat.TRANSLUCENT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    mLayoutParams.type = LayoutParams.TYPE_TOAST;
    Log.d(TAG, "initWindowManager: TYPE_TOAST");
} else {
    mLayoutParams.type = LayoutParams.TYPE_PRIORITY_PHONE;
    Log.d(TAG, "initWindowManager: TYPE_PRIORITY_PHONE");
}
mLayoutParams.setTitle("BaseFloatWindowView");
mLayoutParams.windowAnimations = R.style.anim_MarkPhoneNumWindowView;

设置了Flag为LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH后监听addView中的View的触摸事件

@Override
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_OUTSIDE:
            //相应逻辑
            hide();
            return true;
    }
    return false;
}
阅读 600 · 发布于 2019-04-13

————        END        ————

扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看换一批