美文网首页
Dialog全屏,关闭标题栏,PoupWindos全屏

Dialog全屏,关闭标题栏,PoupWindos全屏

作者: 谭冉冉 | 来源:发表于2016-11-04 15:21 被阅读207次

    全屏

    实现全屏(宽/高度全屏)

    方法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);

    相关文章

      网友评论

          本文标题:Dialog全屏,关闭标题栏,PoupWindos全屏

          本文链接:https://www.haomeiwen.com/subject/yccwuttx.html