【发布时间】:2013-01-27 15:57:24
【问题描述】:
我在Activty 里面有这个custom dialog,它在ActivityGroup 里面。
我希望在外部单击时关闭对话框,并尝试了我在网上找到的所有方法以使其正常工作..
我试过setCanceledOnTouchOutside(true) - 没用
我试过了:
public boolean onTouchEvent ( MotionEvent event ) {
// I only care if the event is an UP action
if ( event.getAction () == MotionEvent.ACTION_UP ) {
// create a rect for storing the window rect
Rect r = new Rect ( 0, 0, 0, 0 );
// retrieve the windows rect
this.getWindow ().getDecorView ().getHitRect ( r );
Log.i(r.toShortString(),r.toShortString());
// check if the event position is inside the window rect
boolean intersects = r.contains ( (int) event.getX (), (int) event.getY () );
// if the event is not inside then we can close the activity
if ( !intersects ) {
// close the activity
this.dismiss ();
// notify that we consumed this event
return true;
}
}
它也没有用..
正如我在 LogCat 中看到的那样 - 我认为出于某种原因 对话框窗口大小是全屏的,这就是为什么我没有“外部”可以触摸的原因..
我认为这可能与活动组有关.. 有什么建议吗?
【问题讨论】:
标签: android android-dialog activitygroup