The Android Developer Challenge is back! Submit your idea before December 2.

BottomSheetDialog

public class BottomSheetDialog
extends AppCompatDialog

java.lang.Object
   ↳ android.app.Dialog
     ↳ androidx.appcompat.app.AppCompatDialog
       ↳ com.google.android.material.bottomsheet.BottomSheetDialog


Base class for Dialogs styled as a bottom sheet.

Summary

Inherited constants

From interface android.content.DialogInterface

Public constructors

BottomSheetDialog(Context context)
BottomSheetDialog(Context context, int theme)

Protected constructors

BottomSheetDialog(Context context, boolean cancelable, DialogInterface.OnCancelListener cancelListener)

Public methods

void cancel()

This function can be called from a few different use cases, including Swiping the dialog down or calling `dismiss()` from a `BottomSheetDialogFragment`, tapping outside a dialog, etc...

BottomSheetBehavior<FrameLayout> getBehavior()
boolean getDismissWithAnimation()

Returns if dismissing will perform the swipe down animation on the bottom sheet, rather than the window animation for the dialog.

void setCancelable(boolean cancelable)
void setCanceledOnTouchOutside(boolean cancel)
void setContentView(View view)
void setContentView(int layoutResId)
void setContentView(View view, ViewGroup.LayoutParams params)
void setDismissWithAnimation(boolean dismissWithAnimation)

Set to perform the swipe down animation when dismissing instead of the window animation for the dialog.

Protected methods

void onCreate(Bundle savedInstanceState)
void onStart()

Inherited methods

From class androidx.appcompat.app.AppCompatDialog
From class android.app.Dialog
From class java.lang.Object
From interface androidx.appcompat.app.AppCompatCallback
From interface android.content.DialogInterface
From interface android.view.Window.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.View.OnCreateContextMenuListener

Public constructors

BottomSheetDialog

BottomSheetDialog (Context context)

Parameters
context Context

BottomSheetDialog

BottomSheetDialog (Context context, 
                int theme)

Parameters
context Context

theme int

Protected constructors

BottomSheetDialog

BottomSheetDialog (Context context, 
                boolean cancelable, 
                DialogInterface.OnCancelListener cancelListener)

Parameters
context Context

cancelable boolean

cancelListener DialogInterface.OnCancelListener

Public methods

cancel

void cancel ()

This function can be called from a few different use cases, including Swiping the dialog down or calling `dismiss()` from a `BottomSheetDialogFragment`, tapping outside a dialog, etc...

The default animation to dismiss this dialog is a fade-out transition through a windowAnimation. Call ERROR(/setDismissWithAnimation(true)) if you want to utilize the BottomSheet animation instead.

If this function is called from a swipe down interaction, or dismissWithAnimation is false, then keep the default behavior.

Else, since this is a terminal event which will finish this dialog, we override the attached BottomSheetBehavior.BottomSheetCallback to call this function, after STATE_HIDDEN is set. This will enforce the swipe down animation before canceling this dialog.

getBehavior

BottomSheetBehavior<FrameLayout> getBehavior ()

Returns
BottomSheetBehavior<FrameLayout>

getDismissWithAnimation

boolean getDismissWithAnimation ()

Returns if dismissing will perform the swipe down animation on the bottom sheet, rather than the window animation for the dialog.

Returns
boolean

setCancelable

void setCancelable (boolean cancelable)

Parameters
cancelable boolean

setCanceledOnTouchOutside

void setCanceledOnTouchOutside (boolean cancel)

Parameters
cancel boolean

setContentView

void setContentView (View view)

Parameters
view View

setContentView

void setContentView (int layoutResId)

Parameters
layoutResId int

setContentView

void setContentView (View view, 
                ViewGroup.LayoutParams params)

Parameters
view View

params ViewGroup.LayoutParams

setDismissWithAnimation

void setDismissWithAnimation (boolean dismissWithAnimation)

Set to perform the swipe down animation when dismissing instead of the window animation for the dialog.

Parameters
dismissWithAnimation boolean: True if swipe down animation should be used when dismissing.

Protected methods

onCreate

void onCreate (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

onStart

void onStart ()