android show dialog

来源:互联网 发布:魔幻现实主义 知乎 编辑:程序博客网 时间:2024/05/17 22:48

用于响应点击dialog  之外的区域

public void showProgressDialog(){

        if(mPd == null || !mPd.isShowing()){

            if(mPd == null){

                mPd = new ProgressDialog(this){

                    public boolean dispatchTouchEvent(MotionEvent ev) {

                        float x =  ev.getX();

                        float y = ev.getY();

                        View dock = getWindow().getDecorView();

                        int[] location = new int [2];

                        dock.getLocationOnScreen(location);

                        boolean ret = super.dispatchTouchEvent(ev);

                        x += location[0];

                        y += location[1];

                        mExpandView.getLocationOnScreen(location);

                        x -= location[0];

                        y -= location[1];

                        ev.setLocation((float)x, (float)y);

                        mExpandView.dispatchTouchEvent(ev);

                        return ret;

                    }

                };

                mPd.setTitle("Loading...");

                mPd.setMessage("Loading...");

                mPd.setIndeterminate(true);

                mPd.setCancelable(true);

                mPd.setOnCancelListener(null);

            }

            mPd.show();

        }

    }