DEV Community

Arnold Wafula
Arnold Wafula

Posted on • Originally published at Medium

Getting Started with Bottom Sheets in Android Using Kotlin Part 1 [Beginner Friendly]

Photo by [Jonathan Kemper](https://unsplash.com/de/@jupp?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/photos/t6Wmvbw_MdI?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)
Hi guys 👋, in this article, I'm going to delve into what a bottom sheet is, its common uses, and how it can be implemented in android development using Kotlin. I will cover its implementation in the traditional view system (XML-based).

Without further ado, we can ask ourselves the question. What is a bottom sheet?

According to Google's material.io documentation, a bottom sheet is a surface containing supplementary content that are anchored to the bottom of the screen and can be dismissed in order to interact with the underlying content.

Its use has been preferred over dialogs in recent years and as a smartphone user either on Android or iOS, you must have interacted with it. Personally an avid YouTube user, it is heavily and perfectly integrated within its U.I.

It is also worth noting that they are flexible and can hold a diverse range of information and layouts, including menu items, actions, and supplemental content.


There are two types of bottom sheets;

  1. Standard bottom sheet
  2. Modal bottom sheet

Standard Bottom Sheet

Also known as persistent bottom sheets, they co-exist with the screens main U.I and allow for simultaneous interaction with both the U.I and itself. It exists in the expanded, collapsed, and hidden states.

A good example of an app that utilizes the standard bottom sheet is Google Maps.
Standard Bottom sheet. Image courtesy of: https://m3.material.io/components/bottom-sheets

Modal Bottom Sheet

Strictly use on mobile devices, modal bottom sheets block interaction with the rest of the screen and serve as a perfect alternative to dialogs, as they provide more room and allow for the use of views such as Images and Text.
Modal bottom sheet. Image courtesy of: https://m3.material.io/components/bottom-sheets

In android development, they extend the BottomSheetDialogFragment class to provide functionalities such as behavior, and screen height among others. In this article, I am going to focus on the modal bottom sheets since they have a more popular use case compared to persistent bottom sheets.

If you wish to go straight into the source code, click the GitHub link below;

GitHub logo arnold-wafula / ModalBottomSheet-Medium

A small project that demonstrates the implementation of the modal bottom sheet in android. Written for my article on medium (Getting Started with Bottom Sheets in Android Using Kotlin [Beginner Friendly])

ModalBottomSheet-Medium

A simple android project that demonstrates the implementation of the modal bottom sheet in android. Written for my article on medium.

main_screen bottom_sheet_dialog

device-2023-02-03-193245.mp4




On Android Studio, Google's official IDE for Android development, navigate to File->New->New Project. Under the templates tab, choose Phone and Tablet and select Empty Activity. Let's start by creating the activity_main layout;

Set up the MainActivity file by copy-pasting the code below;

MainActivity.kt

We will then define the layout for a single item containing an image and text that will appear in the modal bottom sheet. Create a new layout XML file item_bottomsheet and copy-paste the source code below;

item_bottomsheet.xml

Finally, the ModalBottomSheetDialog class displays the items defined in the item_bottomsheet.xml.

ModalBottomSheetDialog.kt

Here is the final result;

Main screen with buttons to launch bottom sheets

bottom sheet displayed

So that is a simple way to build the modal bottom sheet in android. See you in part 2 of the article where I will dive into the fullscreen implementation of the same.

Peace ☮️✌️

Top comments (0)