Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android BottomSheet gray grapple/handle bar

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?

like image 676
VIN Avatar asked Feb 01 '20 04:02

VIN


People also ask

How do I disable BottomSheetDialogFragment dragging?

Disable drag of BottomSheetDialogFragment Even if we have made the BottomSheetDialogFragment as expanded, user can hold the top part of the BottomSheet and drag to show peek view. It can also be disabled by overriding onStateChanged() . This will set the expanded state even if user drags the view.

What is BottomSheetDialogFragment?

↳ com.google.android.material.bottomsheet.BottomSheetDialogFragment. Modal bottom sheet. This is a version of DialogFragment that shows a bottom sheet using BottomSheetDialog instead of a floating dialog.

When to use bottom sheet in android?

Standard bottom sheets display content that complements the screen's primary content. They remain visible while users interact with the primary content. Modal bottom sheets are an alternative to inline menus or simple dialogs on mobile and provide room for additional items, longer descriptions, and iconography.

How can I dim the background when BottomSheet is displayed without using dialog?

Using the Interface - onSlide which as a parameter slideOffSet of type float , can be used to dim the background.


2 Answers

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>
like image 52
VIN Avatar answered Oct 18 '22 20:10

VIN


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.

like image 1
Tejas Mane Avatar answered Oct 18 '22 21:10

Tejas Mane