Android Bottom Sheet Tutorial with Example in Kotlin

Android Bottom Sheet is a component that slides up from the bottom to up in an application. For example, when you have a video to share and you click on the Share button, it will open a one slider form bottom, which contains available apps in your device.

Sometimes it can also have a menu option. In a simple word, the Android Bottom sheet is an area (surface) that containing extra useful content at the bottom of the screen. It’s hidden in the bottom or partial show to the user will be shown to the user on the action.

Android Bottom Sheet Tutorial with Example in Kotlin

In this tutorial, you will learn following:

  1. What is Android Bottom Sheet and it’s type
  2. Example and code of Bottom sheet.

Types of Bottom Sheets

There are two types of bottom sheets, Standard Bottom Sheet and Modal Bottom Sheet.

  • Standard bottom sheets :  Display content that complements the screen’s primary content. Remain visible screen users can interact with the primary content. Like google maps is show in bottom how much time and km etc detail of destination form your point. Here user can interact with both the bottom sheet and the remain of the screen content.
Standard bottom sheet Android
  • Modal bottom sheets: Can be alternative to inline menus or simple dialogs on mobile, providing room for additional items, longer descriptions, and iconography. They must be dismissed in order to interact with the underlying content. Example share the location in google map.
Modal bottom sheet android save

Bottom Sheet behavior and States :

Bottom sheets have 5 states:

STATE_COLLAPSED: The bottom sheet is visible but only showing its peek height. This state is usually the ‘resting position’ of a Bottom Sheet

STATE_EXPANDED: The bottom sheet is visible and its maximum height and it is neither dragging or settling.

STATE_DRAGGING: The user is actively dragging the bottom sheet up or down.

STATE_SETTLING: The bottom sheet is settling to specific height after a drag/swipe gesture. This will be the peek height, expanded height, or 0, in case the user action caused the bottom sheet to hide.

STATE_HIDDEN: The bottom sheet is no longer visible.

Source : https://material.io/develop/android/components/bottom-sheet-behavior/

Let’s Build a Example of Android Bottom Sheet :

Step 1. Create new project “Build Your First Android App in Kotlin
Step 2. Add following color code in “color.xml” layout file
Step 3. Create “bottom_sheet.xml” and Add code

This will be use for standard bottom sheet.

Step 4. Create “bottom_sheet_dialog.xml” and Add code

You must add image in mipmap folder.

Step 5. Create “main_content.xml” and Add code

Its your app main content with 2 Button to perform a show and hide Android Bottom Sheet.

Step 6. Add following code in “activity_main.xml

A holding all xml file (main_content.xml & bottom_sheet.xml) in one place, using <include>...</include>its a good practice to use if your screen have common or long code.

Step 7. Open the “MainActivity.kt” and add following code

Setting a listener in button and handling behaviour or bottom sheet.

Step 8. Now Run the application, in emulator or On you android device
Output screenshot Android Bottom Sheet example :
Android Bottom Sheet Tutorial with Example in Kotlin output

Video Output

Download source code Android BottomSheet in kotlin

Do comment if you have any doubt and suggestion on this tutorial.

Note : This example (Project) is developed in Android Studio 3.1.3 . Tested on Android 9 ( Android-P), compile SDK version API 27: Android 8.0 (Oreo)

MinSdkVersion=”15″

TargetSdkVersion=”27″

Coding in Kotlin


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.