Android Bottom Sheet with BottomSheetDialogFragment
Last updated Dec 06, 2019Hello Guys, Today we are going to learn about BottomSheetDialogFragment.
What is BottomSheet?
Android BottomSheet is a Materail API component that slides up from the bottom of the current state.
We have two types of BottomSheets
- Persistent BottomSheet
- Modal BottomSheet
Persistent BottomSheet:
This Bottomsheet displays inside app content. It will displays with some peek hieght on the screen.
While expanding the sheet it will show the complete view on the screen.
It will be implemented by using BottomSheetBehavior with CoordinateLayout.
Modal BottomSheet
This Bottomsheet works as Dialog on the screen.
This BottomSheet has more elevation that Persistent BottomSheet
It will be implemented by using BottomSheetDialog or BottomSheetDialogFragment
In this Example we are going to learn about BottomSheetDialogFragment
Let's start coading..
Add material dependency in app level gradle file
implementation 'com.google.android.material:material:1.0.0' |
Let's create a layout for bottomsheet
android:id="@+id/tv_bottom_sheet_heading" android:id="@+id/tv_btn_add_photo_camera" android:drawablePadding="16dp" android:layout_width="match_parent" android:id="@+id/tv_btn_add_photo_gallery"
|
activity_main.xml
android:id="@+id/img_upload"
|
PhotoBottomDialogFragment.java
package com.rrtutors.bottomsheetdialog; import android.os.Bundle; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import androidx.annotation.NonNull; public class PhotoBottomDialogFragment extends BottomSheetDialogFragment { |
MainActivity.java
package com.rrtutors.bottomsheetdialog; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {
PhotoBottomDialogFragment bottomDialogFragment=new PhotoBottomDialogFragment(); |
Just run the application and tap on Image, you will able to see the BottomSheetDialog on the screen
Article Contributed By :
|
|
|
|
1849 Views |