本次講的是如何對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); }