Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popwindow全屏覆盖状态栏 #41

Open
wuyunqiang opened this issue Feb 9, 2018 · 0 comments
Open

Popwindow全屏覆盖状态栏 #41

wuyunqiang opened this issue Feb 9, 2018 · 0 comments
Labels

Comments

@wuyunqiang
Copy link
Owner

wuyunqiang commented Feb 9, 2018

statusbarpop.png

    //设置弹出框内容
    public void setContent(final PopupWindow popupWindow,Activity activity){
        LinearLayout linearlayout = (LinearLayout) LayoutInflater.from(activity).inflate(R.layout.share, null);
        View v = linearlayout.findViewById(R.id.background);
        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG,"点击空白区域");
                //popwindow 消失了
                popupWindow.dismiss();
            }
        });
        LinearLayout wechat = linearlayout.findViewById(R.id.wechat);
        wechat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });

        LinearLayout moment = linearlayout.findViewById(R.id.moment);
        moment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow.dismiss();
            }
        });
        View c = linearlayout.findViewById(R.id.cancel);
        c.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //popwindow 消失了
                popupWindow.dismiss();
            }
        });

        //  popupWindow.setOutsideTouchable(false);
        popupWindow.setContentView(linearlayout);
    }

    public void showPopWindow(Activity activity){
        ColorDrawable dw = new ColorDrawable(activity.getResources().getColor(R.color.colorPrimaryDark));
        LinearLayout parent = new LinearLayout(activity);
        final PopupWindow popupWindow = new PopupWindow(parent, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true);
        popupWindow.setTouchable(true);// true popwindow优先一切(系统级以外)处理touch  false:popwindow 只是一个view 不影响界面操作
//        popupWindow.setTouchInterceptor(new View.OnTouchListener() {//并没有什么用
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//                Log.i(TAG, "onTouch ");
//                return false;
//            }
//        });

        this.setContent(popupWindow,activity);
        popupWindow.setBackgroundDrawable(dw);//不设置背景无法点击
        fitPopupWindowOverStatusBar(popupWindow,true);
        popupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);//异步调用 popwindow依赖view oncreate时view并没有建立
    }


    //适配全屏
    public void fitPopupWindowOverStatusBar(PopupWindow popupWindow,boolean needFullScreen) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            try {
                Field mLayoutInScreen = PopupWindow.class.getDeclaredField("mLayoutInScreen");
                mLayoutInScreen.setAccessible(true);
                mLayoutInScreen.set(popupWindow, needFullScreen);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant