自定义DialogFragment

1.配置xml

首先要在最外层定义一个RetiveLayout布局(布局任意),然后在定义一个布局用来显示内容。

2.DialogFragment

1.在onActivityCreated()给dialog设置宽高

Window window = getDialog().getWindow();

ViewGroup.LayoutParams attributes = window.getAttributes();

window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);

2.在onCreateView()设置样式

getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);//无标题

getDialog().setCanceledOnTouchOutside(true);//点击边际可消失

3.在style文件配置.ActionSheetDialogStyle

<style name="ActionSheetDialogStyle"parent="@android:style/Theme.Dialog">        

<item name="android:windowBackground">@android:color/transparent

<item name="android:windowContentOverlay">@null</item>    

<item name="android:windowIsFloating">true</item>    <!-- 边框 -->      

<item name="android:windowFrame">@null</item>  

<item name="android:backgroundDimEnabled">true</item>    <!-- 无标题 -->

<item name="android:windowNoTitle">true</item>    <!-- 半透明 -->  

<item name="android:windowIsTranslucent">true</item>

3.调用

ChooseRoleDialog dialog = new ChooseRoleDialog();

dialog.setStyle(DialogFragment.STYLE_NORMAL,R.style.ActionSheetDialogStyle);

dialog.show(getSupportFragmentManager(),"");

    原文作者:wangmf
    原文地址: https://www.jianshu.com/p/35d1d0f4aeeb
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞