dialogfragment 全屏最简单方案.
在oncreateview,oncreatedialog搞都不是全屏的,只要在oncreate加一句话就可以了:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Light_NoTitleBar); }
主题自己挑喜欢的就行。这里提供了几种方法:https://blog.csdn.net/wangtao0921/article/details/51003353
另外,新建Appcompatdialogfragment后,使用contraintlayout会出现重叠现象,把她的宽度改了就行了。
如果不要全屏,并且不要标题栏,那么如下改动是无效的:
@Override public void onStart() { super.onStart(); Dialog dialog = getDialog(); if (dialog != null) { DisplayMetrics dm = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); dialog.getWindow().setLayout((int) (dm.widthPixels * 0.75), ViewGroup.LayoutParams.WRAP_CONTENT); } }
onCreateView方法中加上:
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
嗯,就是这个兄台说的无效了:https://blog.csdn.net/zhyh1986/article/details/48655885
正确做法是:
1、在onCreateDialog加上:
public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); return dialog; }
2、在onstart加上:
@Override public void onStart() { super.onStart(); Dialog dialog = getDialog(); if (dialog != null) { Window window = dialog.getWindow(); if (window != null) { int width = ViewGroup.LayoutParams.MATCH_PARENT; int height = ViewGroup.LayoutParams.WRAP_CONTENT; window.setLayout(width, height); } } }
这下OK了,如果要比例就按那个没用的试试。