dialogActivity窗口化后避免点击区域外消失的办法

如果API Level>11

方法一:

    

方法二:

Activity.this.setFinishOnTouchOutside(false); 

如果API Level<11

@Override  
    public boolean onTouchEvent(MotionEvent event) {  
        if (event.getAction() == MotionEvent.ACTION_DOWN && isOutOfBounds(this, event)) {  
            return true;  
        }  
        return super.onTouchEvent(event);  
    }  

    private boolean isOutOfBounds(Activity context, MotionEvent event) {  
        final int x = (int) event.getX();  
        final int y = (int) event.getY();  
        final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();  
        final View decorView = context.getWindow().getDecorView();  
        return (x < -slop) || (y < -slop)|| (x > (decorView.getWidth() + slop))|| (y > (decorView.getHeight() + slop));  
    }  

你可能感兴趣的:(dialogActivity窗口化后避免点击区域外消失的办法)