转载请注明链接:https://blog.csdn.net/feather_wch/article/details/88042877
如今一个需求Dialog正好处于一个播放窗口(Fragment)的正中央,原始Dialog的Center属性只能位于窗口的中央,无法满足需求。
Dialog在Fragment中居中显示
版本:2019/2/28-20:02
源码
- Dialog的代码自己实现。
- 通过DialogUtils在show之前进行调整。
// 1、传入Dialog、Fragment、true
DialogUtils.setDialogInFragmentsCenter(mDialog, MyFragment.this, true);
// 2、展示Dialog
mDialog.show();
状态栏的处理
1、具有状态栏,且状态为全屏模式。
DialogUtils.setDialogInFragmentsCenter(mDialog, MyFragment.this, true);
2、没有状态栏(如手机横屏进行全屏播放)、有状态栏但是不会使用到状态栏的区域
DialogUtils.setDialogInFragmentsCenter(mDialog, MyFragment.this, false);
DialogUtils
1、DialogUtils.java源码
/**=======================================
* @author 猎羽
* @function 让Dialog处于指定Fragment的正中间
*=======================================*/
public class DialogUtils
{
private static final String TAG = DialogUtils.class.getName();
/**
*
* @param dialog
* @param fragment
* @param hasStatusBar 该页面是否具有statusBar。有,在不包括状态栏的区域居中;没有,在该整个区域居中。
*/
public