What is BottomSheet ?
Bottom Sheet is a view that slides up from the bottom of the screen.Bottom sheets are displayed as a result of the user-triggered action, and also it can reveal additional content by swiping up.
What are the Types ?
Persistent : It remains visible on the screen.You need to include your bottom sheet inside the main layout.To make a view as persistent Bottom Sheet in your screen all you need to do is have CoordinatorLayout at the top level of your layout.
Modal : Modal bottom sheets are dialogs which are alternatives to content choosers, simple menus or dialogs, and can display deep-linked content from another app. It is similar to a Dialog, for this you need BottomSheetDialogFragment.
How to create a BottomSheet ?
For adding a BottomSheet into your application first, you need to add the design library(>=23.2) into your dependency list.
There are three choices available for creating a BottomSheet, they are listed below
- BottomSheetBehavior : add this behavior to a child view of CoordinatorLayout to make it work as a bottom sheet.
- BottomSheetDialog : It’s like a dialog creation, Create a BottomSheetDialog and you can set the content view for that dialog.
- BottomSheetDialogFragment : This is a version of DialogFragment that shows a bottom sheet using BottomSheetDialog instead of a floating dialog.
BottomSheetDialogFragment uses the BottomSheetDialog as the base inside the fragment, so we discuss other two ways and types of the BottomSheet.
How to implement a Persistent BottomSheet ?
For persistent bottomSheet, you just have to use a CoordinatorLayout as the main element of your layout and attach a BottomSheet behavior to a view .For this use the code below.
How do I configure BottomSheetCallBack ?
You can track the events of the BottomSheet using BottomSheetCallBack. Use the code below for configuring the BottomSheetCallBack with your BottomSheet.
How to implement a Modal BottomSheet ?
Modal BottomSheets are basically Dialog Fragments that slide from the bottom. You can anyone of your layout as a content view of the BottomSheetDialog. So view creation is as usual layout creation, here the code explains to create a BottomSheetDialog and inflate the layout into that dialog.
This ends the blog on BottomSheet in Android. Feel free to comment and share, keep watching this space get more updates on Android Stuff!
Latest posts by Jaison Fernando (see all)
- How to create face detector using Firebase MLKit? - November 29, 2018
- How to create a barcode scanner using Firebase MLKit? - November 9, 2018
- How to update your app using Firebase Remote Config? - October 20, 2018