全屏
实现全屏(宽/高度全屏)
方法1
@Overridepublic Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.fragment_dialog, null); Dialog dialog = new Dialog(getActivity(), R.style.CustomDialog); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(view); dialog.setCanceledOnTouchOutside(true); //Do something // 设置宽度为屏宽、位置靠近屏幕底部 Window window = dialog.getWindow(); window.setBackgroundDrawableResource(R.color.transparent); WindowManager.LayoutParams wlp = window.getAttributes(); wlp.gravity = Gravity.BOTTOM; wlp.width = WindowManager.LayoutParams.MATCH_PARENT; wlp.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setAttributes(wlp); return dialog;}
方法2
@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomDialog);}@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().setCanceledOnTouchOutside(true); View rootView = inflater.inflate(R.layout.fragment_dialog, container, false); //Do something // 设置宽度为屏宽、靠近屏幕底部。 final Window window = getDialog().getWindow(); window.setBackgroundDrawableResource(R.color.transparent); window.getDecorView().setPadding(0, 0, 0, 0); WindowManager.LayoutParams wlp = window.getAttributes(); wlp.gravity = Gravity.BOTTOM; wlp.width = WindowManager.LayoutParams.MATCH_PARENT; wlp.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setAttributes(wlp); return rootView;}
实现关闭标题栏
对于方法 ①
Dialog dialog = new Dialog(getActivity(), R.style.CustomDialog); // 关闭标题栏,setContentView() 之前调用 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(view);
对于方法 ②:
/** * setStyle() 的第一个参数有四个可选值: * STYLE_NORMAL|STYLE_NO_TITLE|STYLE_NO_FRAME|STYLE_NO_INPUT * 其中 STYLE_NO_TITLE 和 STYLE_NO_FRAME 可以关闭标题栏 * 每一个参数的详细用途可以直接看 Android 源码的说明 */ setStyle(DialogFragment.STYLE_NO_TITLE, R.style.CustomDialog);
poupWindos全屏
popupWindow.setClippingEnabled(false);
popupWindow.showAtLocation(getWindow().getDecorView(), Gravity.TOP|Gravity.START,0,0);
网友评论