DialogFragment fullscreen shows padding on sides

后端 未结 11 1594
囚心锁ツ
囚心锁ツ 2020-12-05 00:22

I am creating a custom DialogFragment that is displayed underneath the actionbar. So far everything works great. The layout parameters for dialog fragment are match_pa

11条回答
  •  独厮守ぢ
    2020-12-05 00:37

    First you need to know that handling of full screen in Dialog fragment is different from the normal Dialog component, second you need to customize the Dialog fragment before the actual creation of the dialog @ (OnCreateDialog), according to the answer of "user3244180" Full screen DialogFragment

     @Override
     public Dialog onCreateDialog(final Bundle savedInstanceState) {
    
         // the content
         final RelativeLayout root = new RelativeLayout(getActivity());
         root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    
         // creating the fullscreen dialog
         final Dialog dialog = new Dialog(getActivity());
         dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
         dialog.setContentView(root);
         dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
         dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    
         return dialog;
     }
    

提交回复
热议问题