I want to give margins to the bottom sheet dialog on left and right. I tried a few methods but unfortunately not working.
I have a bottom sheet which opens up when I move to one of the fragment using Bottom Navigation.
This is the Bottom Sheet implemented using BottomSheetDialogFragment which comes up when I click on one of the navigation menu.
Here is the code for that :
class ProfileFragment : BottomSheetDialogFragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_profile_bottom_sheet, container, false)
}
}
And here's how my layout file looks Like :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/transparent"
tools:context=".fragments.ProfileFragment"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:orientation="vertical"
>
<LinearLayout
android:id="@+id/bottomSheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/purple_200"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="8dp"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profile_image"
android:layout_width="96dp"
android:layout_height="96dp"
android:src="@drawable/img_profile"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Akash Sharma"
android:textColor="@color/black"
android:textStyle="bold"
android:textSize="24sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View Profile"
android:fontFamily="sans-serif"
android:layout_marginTop="4dp"
/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="wrap_content"
android:layout_height="2dp"
android:background="#43736C6C"
android:layout_marginTop="8dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="12dp"
android:layout_marginTop="24dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_pen"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Posts"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:textColor="@color/black"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="12dp"
android:layout_marginTop="24dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_groups"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Posts"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:textColor="@color/black"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="12dp"
android:layout_marginTop="24dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_location"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Location"
android:textSize="20sp"
android:layout_marginLeft="10dp"
android:textColor="@color/black"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="12dp"
android:layout_marginTop="24dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_share"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share App"
android:layout_marginLeft="10dp"
android:textSize="20sp"
android:textColor="@color/black"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="12dp"
android:layout_marginTop="24dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_settings"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings & Privacy "
android:layout_marginLeft="12dp"
android:textSize="20sp"
android:textColor="@color/black"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="12dp"
android:layout_marginTop="24dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_feedback"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Give Feedback"
android:layout_marginLeft="12dp"
android:textSize="20sp"
android:textColor="@color/black"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginLeft="12dp"
android:layout_marginTop="24dp"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_signout"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sign Out"
android:layout_marginLeft="12dp"
android:textSize="20sp"
android:textColor="@color/black"
android:layout_marginBottom="16dp"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Define the bottomSheetDialogTheme attribute in styles.xml in your app theme:
Then just define your favorite shape with shapeAppearanceOverlay
then override this method in the custom fragment.