简体   繁体   中英

How to make BottomSheetDialogFragment cover the full screen?

I'm using BottomSheetDialogFragment to show some data.But when I'm starting the fragment it's appearing 50% of the screen .So, my question is how to make it full screen when it shows.

BottomSheetDialogFragment Code:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.bot_frag, container, false);
    TextView tv = v.findViewById(R.id.textVi);
    back=v.findViewById(R.id.back_of_bot);
    back.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    dismiss();
                }
            }
    );
    return v;
}

You can use dialog fragments, plz refer this:

public class DialogFragments extends DialogFragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.dialog_dialogfragment_layout, null);
        getDialog().setTitle("Title");
        return view;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        DisplayMetrics metrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
        getDialog().getWindow().setGravity(Gravity.BOTTOM);
        getDialog().getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, (int) (metrics.heightPixels * 0.30));// here i have fragment height 30% of window's height you can set it as per your requirement
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogAnimationUpDown;

}

and when you want to open,open Bottomsheet dialog like this way :

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.bot_frag, container, false);
    TextView tv = v.findViewById(R.id.textVi);
    back=v.findViewById(R.id.back_of_bot);
    back.setOnClickListener(
            new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   FragmentManager fm = getFragmentManager();
                   DialogFragments dialogFragment = new DialogFragments(this);
                   dialogFragment.show(fm, "Bottomsheet Fragment");
                }
            }
    );
    return v;
}

您必须将此样式应用于您BottomSheetDialogFragment

android.R.style.Theme_Material_Light_NoActionBar_Fullscreen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM