Bottom Sheet (Persistent)
Bottom sheets slides up from the bottom of the screen to reveal content. However, depending on the display of sheets they are categorized into two.
- Persistent Android Bottom Sheet
- Modal Android Bottom Sheet
Persistent Android Bottom Sheet
Persistent bottom sheet are mainly used to display in-app details. Suppose there is an additional content which is useful to the user, you need to show in it. Scenario, in which you are persistent to show content related to your app you will use this type of design.
![]() |
Persistent Bottom Sheet |
Simple example of Persistent Bottom Sheet.
For this you require to create a project in Android Studio. Add the following line under dependencies in build.gradle file of /app folder.
implementation 'com.android.support:design:27.0.2'
The above line will enable you to have all the classes that are required for Bottom Sheet implementation
Now, in your main layout file define the layout container which will act as your Bottom Sheet. In my case I have resorted to RelativeLayout. The below code will help you understand the concept.
<RelativeLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#901973a7"
app:behavior_hideable="false"
app:behavior_peekHeight="120dp"
app:elevation="4dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<TextView
android:id="@+id/bottomsheet_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/details"
android:textColor="#FFFFFF"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
Persistent Bottom Sheet are drag-gable and hide able depending on the boolean value of "app:behaviour_hideable". The attribute "app:behaviour_peekHeight" is used to determine the height which will be visible at initial stage. The attribute which recognizes the layout as Bottom Sheet is "app:layout_behaviour=@string/bottom_sheet_behaviour".
The whole project can be downloaded from here.
Comments
Post a Comment