桌面悬浮框,飘框

 private void showDesk() {
        if(!PerssionUtils.initAlertPermission()){
            return;
        }
        if(  mDeskView!=null){
            return;
        }
        mDeskView = new DeskWindowView(this);
        final WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        int screenWidth = 0, screenHeight = 0;
        if (windowManager != null) {
            //获取屏幕的宽和高
            Point point = new Point();
            windowManager.getDefaultDisplay().getSize(point);
            screenWidth = point.x;
            screenHeight = point.y;
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
//            layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
//            layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
            layoutParams.width = UIUtil.dip2px(200);
            layoutParams.height = UIUtil.dip2px(200);
            //设置type
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                //26及以上必须使用TYPE_APPLICATION_OVERLAY   @deprecated TYPE_PHONE
                layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
            } else {
                layoutParams.type = WindowManager.LayoutParams.TYPE_PHONE;
            }
            //设置flags
            layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
            layoutParams.gravity = Gravity.START | Gravity.TOP;
            //背景设置成透明
            layoutParams.format = PixelFormat.TRANSPARENT;
            layoutParams.x = screenWidth/2-UIUtil.dip2px(100);
            layoutParams.y = screenHeight / 2-UIUtil.dip2px(100);


            //将View添加到屏幕上
            windowManager.addView(mDeskView, layoutParams);
        }
        mDeskView.setOnclikListen(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                assert windowManager != null;
                windowManager.removeView(mDeskView);
                mDeskView=null;
            }
        });
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值