How to make DialogFragment width to Fill_Parent

前端 未结 18 2466
栀梦
栀梦 2020-12-04 08:21

I am working on an android application where I am using DialogFragment to display the dialog but its width is very small. How I can make this width to fil

18条回答
  •  -上瘾入骨i
    2020-12-04 09:10

    This is how i solved when i faced this issue. Try this.

    in your DialogFragment's onActivityCreated, Add this code according to your need....

     @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            myview=inflater.inflate(R.layout.fragment_insurance_detail, container, false);
            intitviews();
            return myview;
        }
        @Override
        public void onActivityCreated(Bundle arg0) {
            super.onActivityCreated(arg0);
            getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
            getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            getDialog().getWindow().setGravity(Gravity.CENTER);
        }
    

提交回复
热议问题