5

This is the layout that I use:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top|center_horizontal"
android:background="@color/white"
android:gravity="top|center_horizontal"
android:orientation="vertical">

    <TextView
        android:id="@+id/provisioningTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Phone Number" />

</LinearLayout>

This is my class that creates the Dialog:

open class DialogProvisioningData : BottomSheetDialog {
constructor(context: Context) : super(context)


private lateinit var mBehavior: BottomSheetBehavior<FrameLayout>

override fun setContentView(view: View) {
    super.setContentView(view)
    val bottomSheet = window.decorView.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout
    mBehavior = BottomSheetBehavior.from(bottomSheet)
    mBehavior.peekHeight = Resources.getSystem().getDisplayMetrics().heightPixels
    mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
}

override fun onStart() {
    super.onStart()
    mBehavior.peekHeight = Resources.getSystem().getDisplayMetrics().heightPixels
    mBehavior.state = BottomSheetBehavior.STATE_EXPANDED
}

companion object {
    fun newInstance(context: Context): DialogProvisioningData {
        val dialog = DialogProvisioningData(context)
        var layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater;
        val bottomSheet = layoutInflater.inflate(R.layout.dialog_provisioning, null)
        bottomSheet.layout.setOnClickListener({ dialog.cancel() })
        dialog.setOnShowListener { dialog ->
            val d = dialog as BottomSheetDialog

            val bottomSheet = d.findViewById<View>(R.id.design_bottom_sheet) as FrameLayout?
            BottomSheetBehavior.from(bottomSheet!!).state = BottomSheetBehavior.STATE_EXPANDED
        }
        dialog.setContentView(bottomSheet)
        dialog.show()
        return dialog
    }
}
}

What do I need to change for the BottomSheetDialog to actually be fullscreen? I've set the state to expanded, and peekHeight set to screen height

rosu alin
  • 5,674
  • 11
  • 69
  • 150
  • Does this answer your question? [Set BottomSheetDialogFragment height to full screen](https://stackoverflow.com/questions/60404985/set-bottomsheetdialogfragment-height-to-full-screen) – Ryan M Mar 10 '22 at 01:52

3 Answers3

0

We can solve it by setting our view.minHeight like this :

class SortProductBottomSheet : BaseBottomSheet() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View = inflater.inflate(R.layout.dialog_blablabla, container, false)-

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        //THIS IS OUR LIFESAVER
        val dm = Resources.getSystem().displayMetrics
        val rect = dm.run { Rect(0, 0, heightPixels, widthPixels) }
        view.minimumHeight = rect.height()
    }

} 
zihadrizkyef
  • 1,849
  • 3
  • 23
  • 46
-1

Don't use fullscreen BottomSheet. you can use from DialogFragment

for showing dialog :

  FragmentManager fragmentManager = getSupportFragmentManager();
    DialogFullscreenFragment newFragment = new DialogFullscreenFragment();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    transaction.add(android.R.id.content, newFragment).addToBackStack(null).commit();

DialogFullscreenFragment class:

public class DialogFullscreenFragment extends DialogFragment {


private View root_view;
private Slider slider;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    root_view = inflater.inflate(R.layout.dialog_event, container, false);


    return root_view;
}


@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    return dialog;
}

}
Mehrdad
  • 1,477
  • 15
  • 17
  • 1
    I don't want a Fragment, I am ok with using a CustomDialog instead of BottomSheetView. But I don't want to have another Fragment in my activity. So I would prefer not to use DialogFragment – rosu alin Sep 03 '19 at 10:17
  • if the original question is about BottomSheetDialog, why would you suggest to change the whole logic? – Alberto M Oct 18 '22 at 04:46
-3

After multiple implementations tried, this was what I was mostly happy. It's full screen, it's a dialog, and it also has the correct SlideUpAnimation that I needed on it. Also, it's easy to call if from inside a fragment without needing to dismiss my own fragment:

open class DialogProvisioningData : Dialog {
constructor(context: FragmentActivity, themeResId: Int) : super(context, themeResId)

    companion object {
        val TAG: String = "DialogProvisioningData"

        fun newInstance(context: FragmentActivity): DialogProvisioningData {
            val dialog = DialogProvisioningData(context, R.style.DialogAnimation)
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
            dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation
            var layoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
            val bottomSheet = layoutInflater.inflate(R.layout.dialog_provisioning, null)

            dialog.setContentView(bottomSheet)
            dialog.show()
            return dialog
        }
    }
}
rosu alin
  • 5,674
  • 11
  • 69
  • 150