Create Drawable Res
bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@color/white"/> <corners android:topLeftRadius="15dp" android:topRightRadius="15dp"/> </shape>
themes.xml
<style name="BottomSheet" parent="Theme.Material3.Light.BottomSheetDialog"> <item name="bottomSheetStyle">@style/Model</item> </style> <style name="Model" parent="Widget.Material3.BottomSheet.Modal"> <item name="android:background">@drawable/bottom_sheet</item> </style>
Create buttom sheet demo.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:id="@+id/mastersheet" android:background="@drawable/bottom_sheet"> <LinearLayout android:id="@+id/main_sheet" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="16dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancle" android:textStyle="normal" android:layout_marginLeft="10dp" android:textSize="18sp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Add Item" android:textStyle="bold" android:textColor="@color/black" android:textSize="20sp" android:gravity="center_horizontal" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#aaaaaa"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10dp"> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:src="@drawable/camera" android:layout_marginLeft="10dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Open Camera" android:textColor="@color/black" android:gravity="center_horizontal" android:textStyle="bold"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10dp"> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:src="@drawable/documents" android:layout_marginLeft="10dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Open Document" android:textColor="@color/black" android:gravity="center_horizontal" android:textStyle="bold"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10dp"> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:src="@drawable/file" android:layout_marginLeft="10dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Open File" android:textColor="@color/black" android:gravity="center_horizontal" android:textStyle="bold"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10dp"> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:src="@drawable/notes" android:layout_marginLeft="10dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Open Notes" android:textColor="@color/black" android:gravity="center_horizontal" android:textStyle="bold"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="10dp"> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:src="@drawable/photos" android:layout_marginLeft="10dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Open Photos" android:textColor="@color/black" android:gravity="center_horizontal" android:textStyle="bold"/> </LinearLayout> </LinearLayout>
Java
/*-- Global Variable --*/ Button open; BottomSheetDialog sheetDialog; /*--- On Create --- */ open = findViewById(R.id.open); open.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { sheetDialog = new BottomSheetDialog(MainActivity.this, R.style.BottomSheet); /*-- First Method--*/ /* View myview = getLayoutInflater().inflate(R.layout.bottom_sheed_dmo, null, false); LinearLayout layout = myview.findViewById(R.id.mastersheet); sheetDialog.setContentView(myview); sheetDialog.show(); */ /*-- First Method End--*/ /*-- Second Method--*/ sheetDialog.setContentView(R.layout.bottom_sheed_dmo); sheetDialog.show(); /*-- Second Method End--*/ } });