对话框样式Activity获得窗口外点击事件

来源:互联网 发布:怎么开一个淘宝店铺 编辑:程序博客网 时间:2024/06/17 12:53

在API11之后添加了setFinishOnTouchOutside()方法,只需要在onCreate()方法中调用:
this.setFinishOnTouchOutside(false);

API11之前

public class MyActivity extends Activity { @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    // Make us non-modal, so that others can receive touch events.    getWindow().setFlags(LayoutParams.FLAG_NOT_TOUCH_MODAL, LayoutParams.FLAG_NOT_TOUCH_MODAL);    // ...but notify us that it happened.    getWindow().setFlags(LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);    // Note that flag changes must happen *before* the content view is set.    setContentView(R.layout.my_dialog_view);  }  @Override  public boolean onTouchEvent(MotionEvent event) {    // If we've received a touch notification that the user has touched    // outside the app, finish the activity.    if (MotionEvent.ACTION_OUTSIDE == event.getAction()) {      finish();      return true;    }    // Delegate everything else to Activity.    return super.onTouchEvent(event);  }}


http://www.cnblogs.com/lcyty/p/3426946.html

原创粉丝点击