WindowManager 相关
WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams params = new WindowManager.LayoutParams();
params.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
params.gravity = Gravity.BOTTOM | Gravity.END;
params.format = PixelFormat.TRANSLUCENT;
params.token = view.getWindowToken(); // 注意使用布局中具体的view
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.x = 20; // 单位 px
params.y = 200;
windowManager.addView(evaluateView, params);
// 也可
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
params.type = WindowManager.LayoutParams.TYPE_PHONE;
}else{
params.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
}
网友评论