- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我已经搜索了有关关闭对话框 onTouchOutside 的所有答案,但是,我在我的应用程序中使用了 DialogFragment。当用户在 DialogFragment 的 区域之外点击时,如何实现关闭 DialogFragment。
我检查了 Dialog 的 source code对于 setCanceledOnTouchOutside
public void setCanceledOnTouchOutside(boolean cancel) {
if (cancel && !mCancelable) {
mCancelable = true;
}
mCanceledOnTouchOutside = cancel;
}
还有另一个可能很有趣的函数是 isOutOfBounds
private boolean isOutOfBounds(MotionEvent event) {
final int x = (int) event.getX();
final int y = (int) event.getY();
final int slop = ViewConfiguration.get(mContext).getScaledWindowTouchSlop();
final View decorView = getWindow().getDecorView();
return (x < -slop) || (y < -slop)
|| (x > (decorView.getWidth()+slop))
|| (y > (decorView.getHeight()+slop));
}
但我不知道如何将这些用于 DialogFragment
除此之外,我还使用 hierarchyviewer 检查了应用程序的状态。据我了解,我只能看到对话框的区域,而不是它的外部部分(我的意思是 DialogFragment 之后屏幕的剩余部分)。
您能否建议一种为 DialogFragment 实现此 setCanceledOnTouchOutside 的方法,并在可能的情况下使用示例代码?
最佳答案
答案很简单:
MyDialogFragment fragment = new MyDialogFragment(); // init in onCreate() or somewhere else
...
if ( fragment.getDialog() != null )
fragment.getDialog().setCanceledOnTouchOutside(true); // after fragment has already dialog, i. e. in onCreateView()
见 http://developer.android.com/reference/android/app/DialogFragment.html#setShowsDialog%28boolean%29有关 DialogFragments 中的对话框的更多信息。
关于android - 关闭 DialogFragment(不是 Dialog)onTouchOutside,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8734303/
我已经搜索了有关关闭对话框 onTouchOutside 的所有答案,但是,我在我的应用程序中使用了 DialogFragment。当用户在 DialogFragment 的 区域之外点击时,如何实现
我是一名优秀的程序员,十分优秀!