Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
}
like image 398
anonymous Avatar asked Dec 01 '17 07:12

anonymous


People also ask

How do I make BottomSheetDialogFragment full screen?

add a view with "android:layout_height="match_parent" into root layout. when dialog is shown (or before this) update of BottomSheetBehavior with "isFitToContents = false" and "state = BottomSheetBehavior.

How do I disable BottomSheetDialogFragment dragging?

Disable drag of BottomSheetDialogFragment It can also be disabled by overriding onStateChanged() . This will set the expanded state even if user drags the view.


1 Answers

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;
}
like image 146
Nilam Vaddoriya Avatar answered Nov 07 '22 07:11

Nilam Vaddoriya