10

I've seen this sort of gray handle bar decoration on BottomSheets in a few popular apps. This is a screenshot of a BottomSheet in Google Maps. Notice the gray handle/gripper at the top of the BottomSheet.

What is the best way to implement a decoration or background like this? Is there a standard material or Android style for this decoration?

VIN
  • 6,385
  • 7
  • 38
  • 77

3 Answers3

9

I inserted an SVG for the grapple/handle into my layout for the bottom sheet.

MyBottomSheetDialogFragmentLayout.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/bottomSheetGrapple"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/topMargin"
        android:src="@drawable/ic_bottom_sheet_grapple"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    .... // rest of layout
</androidx.constraintlayout.widget.ConstraintLayout>

ic_bottom_sheet_grapple.xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="3dp"
    android:viewportWidth="24"
    android:viewportHeight="3">

    <path
        android:fillColor="@android:color/darker_gray"
        android:pathData="M 1.5 0 L 22.5 0 Q 24 0 24 1.5 L 24 1.5 Q 24 3 22.5 3 L 1.5 3 Q 0 3 0 1.5 L 0 1.5 Q 0 0 1.5 0 Z"
        android:strokeWidth="1" />
</vector>
VIN
  • 6,385
  • 7
  • 38
  • 77
1

Also You can add programmatically

private fun addLine() {
    val bottomSheet = requireDialog().findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as? FrameLayout
    val line = View(context)
    val frameLayoutParams =  FrameLayout.LayoutParams(dip(180), dip(6))
    frameLayoutParams.gravity = Gravity.CENTER_HORIZONTAL
    frameLayoutParams.topMargin = dip(16)
    line.layoutParams = frameLayoutParams
    line.setBackgroundResource(R.drawable.rounded_tv_grey)
    line.backgroundTintList = ColorStateList.valueOf(Color.rgb(226, 231, 233))
    bottomSheet?.addView(line,0)
    requireView().updatePadding(requireView().paddingLeft,dip(24),requireView().paddingRight, requireView().paddingBottom)
}
Sven Eberth
  • 3,057
  • 12
  • 24
  • 29
Enciyo
  • 52
  • 1
  • 5
  • Welcome to StackOverflow. While this code may answer the question, providing additional context regarding *how* and/or *why* it solves the problem would improve the answer's long-term value. – Sven Eberth Jul 01 '21 at 17:26
0

Use MaterialCardView

<com.google.android.material.card.MaterialCardView
    android:layout_width="40dp"
    android:layout_height="5dp"
    android:backgroundTint="@color/ms_material_grey_400"
    app:layout_constraintStart_toStartOf="parent"
    android:layout_marginTop="10dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"/>

Use can configure the dimensions and corner radius as per your needs.

Tejas Mane
  • 131
  • 1
  • 5