Connect with us

Hi, what are you looking for?

Latest

Behavior of the bottom sheet in Android

Welcome, Buddy. In this Android training guide, we examine the behavior of the bottom leaves in Android. We will see what Lower Leaf Behavior is, how it works, and we will learn what phase of the Lower Leaf Behavior implementation is in. Then let’s get started.

What are bottom leaves?

Background pages are interface items that contain additional content. It is usually attached to the lower edge of the screen. Simply put, BottomSheet is a hardware design component that slides up from the bottom of the screen to display additional content.

Use

Subsheets are additional surfaces used on mobile devices. There are two types, which are suitable for different purposes:

Modal background sheets – an alternative to your mobile phone’s built-in dialogs and provides space for descriptions and iconography. which opens from the bottom when interacting with the user. If you want to communicate something, an option like this appears at the bottom. For the model on the back I wrote a separate article here.

Persistent Bottom Sheet – provides a wrap-around interface that can be expanded through user interaction (drag and drop, click a button), access to an important function. Simply put, you say that stubborn people can get out of control at any time.

Continuous bottom sheet

It is also known as BottomSheetBehavior. It works with CoordinatorLayout and displays the content above the main layout. The bottom sheet is a well-written hardware design element that improves input/output animation, reacts to drag-and-drop/wipe movements, etc.

Rigid base plate installation step

  • Configure the project and add hardware to the design.
  • Prepare the layout of the bottom sheet.
  • Light the lower blade with the main contents.
  • Click on the activity sheet below.
  • Check the application template.

Guys, I’ll make a sample application now by following the step above. So, let’s get started.

1. Project modification and addition of materials io dependent on design

Let’s open an Iroid studio with Iroidx and add the dependency on Io hardware.

the implementation of androidx.appcompat:appcompat:1.1.0

the implementation of the androidx.constraint layout:constraint layout:1.1.3 application

Implementation ‘androidx.appcompat:appcompat:1.1.0’ Implementation ‘androidx.constraintlayout:constraintlayout:1.1.3’.

Implementation of androidx.appcompat:appcompat:1.1.0
Implementation of androidx.constraint layout:constraint layout:1.1.3

1.1 Open the file color.xml and add colors under.

#008577>Color>

#00574B>/Color>

#6646ee

#fff>Color>Color>

#008577 #00574B #6646ee #fff .



#008577
#00574B
#6646ee
#fff
.

1.2 Adding some filenames

16dp

24dp

16sp

16dp>

16dp 24dp 16sp 16dp .



16dp
24dp
16sp
16dp
.

1.3 Adding a style to the bottom drawing button in style.xml

.

2. Preparation of the layout of the background form

In the res -> layout folder, create an XML file of the layout called bottom_sheet.xml and enter the code below.

xmlns:app=http://schemas.android.com/apk/res-auto

android:[email protected]+id/bottom_sheet

android: layout_width=match_parent

android: layout_height=wrap_content

android: background=#fff

android: orientation=vertical

app:behavior_hideable=wrong

app:behavior_peekHeight=72dp

app:layout_behavior=com.google.android.material.bottomsheet.BottomsheetBehavior

android: [email protected]+id/constraintLayout

android: layout_width=0dp

android: layout_height=wrap_content

android: [email protected]/colorAccent

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:layout_constraintTop_toTopOf= higher

android:[email protected]+id/picture display

android: layout_width=60dp

android: layout_height=60dp

android: layout_marginBottom=8dp

android: layout_marginLeft=8dp

android: layout_marginStart=8dp

android: layout_marginTop=8dp

app:layout_constraintBottom_toBottomOf=parent

app:layout_constraintStartOf=higher

app:layout_constraintTop_toTopOf= higher

app:[email protected]/user_image

android: [email protected]+id/text display

android: layout_width=0dp

android: layout_height=wrap_content

android: layout_marginEnd=8dp

android: layout_marginLeft=16dp

android: layout_marginRight=8dp

android: layout_marginStart=16dp

android: layout_marginTop=8dp

android:text=Loren Kushwaha

android: [email protected]/colorWhite

app:layout_constraintEnd_toEndOf=higher

app:[email protected]+id/imageView

app:[email protected]+id/imageView

android:[email protected]+id/textView2

android: layout_width=0dp

android: layout_height=wrap_content

android: layout_marginEnd=8dp

android: layout_marginLeft=16dp

android: layout_marginRight=8dp

android: layout_marginStart=16dp

android: layout_marginTop=2dp

android:[email protected]

android: [email protected]/colorWhite

app:layout_constraintEnd_toEndOf=higher

app:[email protected]+id/imageView

app:[email protected]+id/textView

android: layout_width=wrap_content

android: layout_height=wrap_content

android: layout_marginLeft=8dp

android: layout_marginStart=8dp

android: [email protected]/ic_call

android: [email protected]/colorAccent

app:[email protected]+id/button3

app:layout_restrictionHorizontal_preload=0.5

app:layout_constraintStartOf=higher

app:[email protected]+id/button3

android: [email protected]+id/button2

android: layout_width=wrap_content

android: layout_height=wrap_content

android: layout_marginEnd=8dp

android: layout_marginLeft=8dp

android: layout_marginRight=8dp

android: layout_marginStart=8dp

android:[email protected]/ic_save

android: [email protected]/colorAccent

app:layout_constraintEnd_toEndOf=higher

app:layout_restrictionHorizontal_preload=0.5

app:[email protected]+id/button3

app:[email protected]+id/button3

android: [email protected]+id/button3

android: layout_width=wrap_content

android: layout_height=wrap_content

android: layout_marginLeft=16dp

android: layout_marginStart=16dp

android: layout_marginTop=24dp

android: [email protected]: colors/transparent

android:[email protected]/ic_website

android: [email protected]/colorAccent

app:[email protected]+id/button2

app:layout_restrictionHorizontal_preload=0.5

app:[email protected]+id/button

app:[email protected]+id/constraintLayout

android:[email protected]+id/textView3

android: layout_width=0dp

android: layout_height=1dp

android: layout_marginTop=24dp

android: background=#ed

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:[email protected]+id/button3

android:[email protected]+id/textView4

android: layout_width=0dp

android: layout_height=wrap_content

android: layout_marginEnd=8dp

android: layout_marginLeft=8dp

android: layout_marginRight=8dp

android: layout_marginStart=8dp

android: layout_marginTop=8dp

android: text=Tutorials for developing applications for Android and iOS for Firebase, Camera2 API, Exo Player, Youtube API, Dagger2, RxJava, MVVM, MVP, Realm, etc.

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:[email protected]+id/textView3

android:[email protected]+id/textView5

android: layout_width=0dp

android: layout_height=1dp

android: layout_marginTop=8dp

android: background=#ed

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:[email protected]+id/textView4

android:[email protected]+id/textView6

android: layout_marginTop=8dp

android:[email protected]/action_keep

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:[email protected]+id/textView5

[email protected]/bottom_sheet_item

android:[email protected]+id/textView7

android: [email protected]/action_inbox

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:[email protected]+id/textView6

[email protected]/bottom_sheet_item

android:[email protected]+id/textView8

android: [email protected]/action_hangout

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:[email protected]+id/textView7

[email protected]/bottom_sheet_item

[email protected]+id/bottom_sheet android:layout_width=match_parent android:layout_height=wrap_content android:background=#fff android:orientation=vertical app:behavior_hideable=false app:behavior_peekHeight=72dp app:layout_behavior=com.google.android.material.bottomsheet.BottomsheetBehavior > [email protected]+id/constraintLayout android:layout_width=0dp android:layout_height=wrap_content android:[email protected]/colorAccent app:layout_constraintEnd_toEndOf=parent app :layout_constraintStart_toStartOf=parent app:layout_constraintTopOf=parent > < android image display:[email protected]+id/android image display:layout_width=60dp android :layout_height=60dp android:layout_marginBottom=8dp android:layout_marginLeft=8dp android:layout_marginStart=8dp android:layout_marginTop=8dp app:layout_constraintBottom_toBottomOf=parent application :layout_constraintStart_toStartOf=parent app:layout_constraintTop_toTopOf=parent app:[email protected]/user_image /> [email protected]+id/textView android:layout_width=0dp android:layout_height=wrap_content android:layout_marginEnd=8dp android:layout_marginLeft=16dp android:layout_marginRight=8dp android :layout_marginStart=16dp android:layout_marginTop=8dp android:text=Loren Kushwaha android:[email protected]/colorWhite android:textSize=18sp app:layout_constraintEnd_toEndOf=parent application :[email protected]+id/imageView app:[email protected]+id/imageView /> [email protected]+id/textView2 android:layout_width=0dp android :layout_height=Wrap_content android:layout_marginEnd=8dp android:layout_marginLeft=16dp android:layout_marginRight=8dp android:layout_marginStart=16dp android:layout_marginTop=2dp android:[email protected] android:[email protected]/color app:layout_constraintEnd_toEndOf=parent app:[email protected]+id/imageView app:[email protected]+id/textView /> [email protected]+id/knot android:layout_width=wrap_content android:layout_height=wrap_content android:layout_marginLeft=8dp android:layout_marginStart=8dp android :[email protected]/ic_call android:text=Call android:[email protected]/colorAccent app:[email protected]+id/button3 app:layout_constraintHorizontal_bias=0.5 app:layout_constraintStart_toStartOf=parent app:[email protected]+id/button3 /> [email protected]+id/button2 android:layout_width=wrap_content android:layout_height=wrap_content android:layout_marginEnd=8dp android:layout_marginLeft=8dp android:layout_marginRight=8dp android :layout_marginStart=8dp android:[email protected]/ic_save android:text=Save android:[email protected]/colorAccent app:layout_constraintEnd_toEndOf=parent app:layout_constraintHorizontal_bias=0.5 app:[email protected]+id/button3 app:[email protected]+id/button3 /> [email protected]+id/button3 android:layout_width=wrap_content android:layout_height=wrap_content android:layout_marginLeft=16dp android:layout_marginStart=16dp android:layout_marginTop=24dp android :[email protected]@@android:color/transparent android:[email protected]/ic_website android:text=Website android:[email protected]/colorAccent app:[email protected]+id/button2 app:layout_constraintHorizontal_bias=0.5 app:[email protected]+id/knot app:[email protected]+id/constraintLayout /> [email protected]+id/textView3 android:layout_width=0dp android:layout_height=1dp android :layout_marginTop=24dp android:background=#eded app:layout_constraintEnd_toEndOf=parent app:layout_constraintStart_toStartOf=parent app:[email protected]+id/button3 /> [email protected]+id/textView4 android:layout_width=0dp android:layout_height=Wrap_content android:layout_marginEnd=8dp android:layout_marginLeft=8dp android:layout_marginRight=8dp android:layout_marginStart=8dp android :layout_marginStart=8dp:layout_marginTop=8dp android:layout_marginTop:text=How to develop Android & iOS applications for Firebase, Camera2 API, Exo Player, Youtube API, Dagger2, RxJava, MVVM, MVP, Realm etc… view android:textSize=16sp app:layout_constraintEnd_toEndOf=parent app:layout_constraintStart_toStartOf=parent app:[email protected]+id/textView3 /> [email protected]+id/textView5 android:layout_width=0dp android:layout_height=1dp android:layout_marginTop=8dp android :background=#eded app:layout_constraintEnd_toEndOf=parent app:layout_constraintStartOf=parent app:[email protected]+id/textView4 /> [email protected]+id/textView6 android:layout_marginTop=8dp android:[email protected]/action_keep app:layout_constraintEnd_toEndOf=parent application layout_constraintStartOf=parent app:[email protected]+id/textView5 [email protected]/bottom_sheet_item /> [email protected]+id/textView7 android:[email protected]/action_inbox app:layout_constraintEnd_toEndOf=parent app: layout_constraintStart_toStartOf=parent app :[email protected]+id/textView6 [email protected]/bottom_sheet_item /> [email protected]+id/textView8 android:[email protected]/action_hangout app :layout_constraintEnd_toEndOf=parent app:layout_constraintStartOf=parent app:[email protected]+id/textView7 [email protected]/bottom_sheet_item /> .


xmlns:app=http://schemas.android.com/apk/res-auto
android:[email protected]+id/bottom_sheet
android:layout_width=match_parent
android:layout_height=wrap_content
android:background=#fff
android:orientation=vertical
app:behavior_hideable=false
app:behavior_peekHeight=72dp
app:layout_behavior=com.google.android.material.bottomsheet.BottomsheetBehavior
>
android:[email protected]+id/constraintLayout
android:layout_width=0dp
android:layout_height=wrap_content
android:[email protected]/colorAccent
app :layout_constraintEnd_toEndOf=higher
app:layout_constraintStart_toStartOf=higher
app:layout_constraintTop_toTopOf=higher
>

[email protected]+id/imageViewandroid:layout_width=60dpandroid:layout_height=60dpandroid:layout_marginBottom=8dpandroid:layout_marginLeft=8dpandroid:layout_marginStart=8dpandroid:layout_marginTop=8dpapp:layout_constraintBottom_toBottomOf=parent app :layout_constraintStart_toStartOf=parent app:layout_constraintTop_toTopOf=parent app:[email protected]/user_image/>[email protected]+id/textViewandroid:layout_width=0dpandroid:layout_width=0dpandroid:layout_height=wrap_contentandroid:layout_marginEnd=8dpandroid:layout_marginLeft=16dpandroid :layout_marginRight=8dpandroid:layout_marginStart=16dpandroid:layout_marginTop=8dpandroid:text=Loren [email protected]/ Colorandroid:textSize=18spapp:layout_constraintEnd_toEndOf=parentapp:[email protected]+id/imageViewapp :[email protected]+id/imageView/>[email protected]+id/textView2android:layout_width=0dpandroid:layout_height=wrap_contentandroid :layout_marginEnd=8dpandroid:layout_marginLeft=16dpandroid:layout_marginRight=8dpandroid:layout_marginStart=16dpandroid:layout_marginTop=2dpandroid:[email protected]:[email protected]/colorWhiteapp:layout_constraintEnd_toEndOf=pairtapp:[email protected]+id/imageViewapp:[email protected]+id/textView/>[email protected]+id/buttonandroid:layout_wrap_contentandroid:layout_height=wrap_contentandroid:layout_marginLeft=8dpandroid:layout_marginStart=8dpandroid :[email protected]/ic_callandroid:text=Callandroid:[email protected]/colorAccentapp:[email protected]+id/button3app:layout_constraintHorizontal_bias=0.5app:layout_constraintStart_toStartOf=pairtapp:[email protected]+id/button3/>[email protected]+id/button2android:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:layout_marginEnd=8dpandroid:layout_marginLeft=8dpandroid:layout_marginRight=8dpandroid :layout_marginStart=8dpandroid:[email protected]/ic_saveandroid:text=Saveandroid:[email protected]/colorAccentapp:layout_constraintEnd_toEndOf=pairtapp:layout_constraintHorizontal_bias=0.5app:[email protected]+id/button3app:[email protected]+id/button3/>[email protected]+id/button3android:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:layout_marginLeft=16dpandroid:layout_marginStart=16dpandroid:layout_marginTop=24dpandroid :[email protected]:color/transparentandroid:[email protected]/ic_websiteandroid:text=Websiteandroid:[email protected]/olorAccentapp:[email protected]+id/button2app:layout_constraintHorizontal_bias=0.5app:[email protected]+id/buttonapp:[email protected]+id/constraintLayout/>[email protected]+id/textView3android:layout_width=0dpandroid:layout_height=1dpandroid :layout_marginTop=24dpandroid:background=#ededapp:layout_constraintEnd_toEndOf=pairtapp:layout_constraintStart_toStartOf=pairtapp:[email protected]+id/button3/>[email protected]+id/textView4android:layout_width=0dpandroid:layout_height=wrap_contentandroid:layout_marginEnd=8dpandroid:layout_marginLeft=8dpandroid:layout_marginRight=8dpandroid :layout_marginStart=8dpandroid:layout_marginTop=8dpandroid:text=How to develop applications for Android & iOS for Firebase, Camera2 API, Exo Player, Youtube API, Dagger2, RxJava, MVVM, MVP, Realm etc… displayandroid:textSize=16spapp:layout_constraintEnd_toEndOf=pairtapp:layout_constraintStart_toStartOf=pairtapp:[email protected]+id/textView3/>[email protected]+id/textView5android:layout_width=0dpandroid:layout_width=1dpandroid:layout_marginTop=8dpandroid:background=#ededapp:layout_constraintEnd_toEndOf=pairtapp :layout_constraintStart_toStartOf=pairtapp:[email protected]+id/textView4/>[email protected]+id/textView6android:layout_marginTop=8dpandroid :[email protected]/action_keepapp:layout_constraintEnd_toEndOf=pairtapp:layout_constraintStart_toStartOf=pairtapp:[email protected]+id/[email protected]/bottom_sheet_items.

/>
android:[email protected]+id/textView7
android:[email protected]/action_inbox
app:layout_constraintEnd_toEndOf=parent
app :layout_constraintStart_toStartOf=parent
app:[email protected]+id/textView6
[email protected]/bottom_sheet_item
/>
android :[email protected]+id/textView8
android:[email protected]/action_hangout
app:layout_constraintEnd_toEndOf= older
app:layout_constraintStart_toStartOf= older
app:[email protected]+id/textView7
[email protected]/bottom_sheet_item
/>

If you have seen the code above, I have some extra tags like layout_behavior, behavior_hideable, behavior_peekHeight, etcetera. Don’t worry, I’ll explain them all in detail.

I applied the behaviour by adding the xml attribute

app:layout_behavior=com.google.android.material.bottomsheet.BottomsheetBehavior

app:layout_behavior=com.google.android.material.bottomsheet.BottomsheetBehavior

app:layout_behavior=com.google.android.material.bottomsheet.BottomsheetBehavior

You can define the following behavioral characteristics

  • app:behavior_hideable – its boolean flag, true means if the bottom leaf can be hidden by dragging it
  • app:behavior_peekHeight – PeepHeight for freefall state.
  • app:behavior_skipCollapsed – if the bottom sheet app:behavior_hideable is true and this value is set to true, it has no wrapped state.

3. Light the lower sheet with the main contents.

So let’s open the share file into which you want to insert the lower part. BottomSheetBehavior only works with CoordinatorLayout. That means he must be a direct child. Open the file presenting the activity and enter a code below.

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=match_parent

tools:context=.mainActivity

android: layout_width=match_parent

android: layout_height=match_parent

app:[email protected]/appbar_scrolling_view_behavior

android: [email protected]+id/textView10

android: layout_width=wrap_content

android: layout_height=wrap_content

android:text= This is an example for the BottomSheet Behaviour application.

android: [email protected]/colorPrimaryDark

app:layout_constraintBottom_toBottomOf=parent

app:layout_restrictionHorizontal_preload=0.0

app:layout_constraintLeft_toLeftOf=parent

app:layout_constraintRight_toRightOf=parent

app:layout_constraintTop_toTopOf= higher

app:layout_restrictionVertical_preload=0.054

android:[email protected]+id/buttonToggleBottomSheet

android: layout_width=wrap_content

android: layout_height=wrap_content

android: layout_marginEnd=8dp

android: layout_marginLeft=8dp

android: layout_marginRight=8dp

android: layout_marginStart=8dp

android: layout_marginTop=16dp

android: text=bottom sheet

app:layout_constraintEnd_toEndOf=higher

app:layout_restrictionHorizontal_preload=0.497

app:layout_constraintStartOf=higher

app:[email protected]+id/textViewState

android:[email protected]+id/textViewState

android: layout_width=wrap_content

android: layout_height=wrap_content

android: layout_marginEnd=8dp

android: layout_marginLeft=8dp

android: layout_marginRight=8dp

android: layout_marginStart=8dp

android: layout_marginTop=16dp

android: [email protected]/colorAccent

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:[email protected]+id/textView10

tools: text=Basic sheet behavior status

[email protected]/bottom_sheet/>

[email protected]/appbar_scrolling_view_behavior > [email protected]+id/textView10 android:layout_wrap_content android:layout_height=wrap_content android :layout_height=wrap_content android:This is an example of the behaviour of the bottom sheet Application android:[email protected]/colorPrimaryDark android:textSize=16sp app:layout_constraintBottomOf=parent app:layout_constraintHorizontal_bias=0.0 app:layout_constraintLeft_toLeftOf=parent app:layout_constraintRightOf=parent app:layout_constraintTop_toTopOf=parent app:layout_constraintVertical_bias=0.054 />

You May Also Like