android Activity區域監聽

本次講的是如何對activity的區域進行監聽,當點擊它以外的區域時執行finish的操作.

@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		if(event.getAction() == MotionEvent.ACTION_UP){
			Rect rect = new Rect(0, 0, 0, 0);
			this.getWindow().getDecorView().getHitRect(rect);
			if(!rect.contains((int)event.getX(), (int)event.getY())){
				finish();
			}
		}
		return super.onTouchEvent(event);
	}

猜你喜欢

转载自bgj.iteye.com/blog/1743114