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.

<?xml Version=1.0 Encryption=utf-8? >

<Color name=ColorPriminal>#008577>Color>

<Color name=ColorPrimaryDark>#00574B>/Color>

<Colour name=colour accent>#6646ee</colour>

<Color name=Color white>#fff>Color>Color>

<?xml version=1.0 encoding=utf-8?> <resources> <color name=colorPrimary>#008577</color> <color name=colorPrimaryDark>#00574B</color> <color name=colorAccent>#6646ee</color> <color name=colorWhite>#fff</color> </resources>.

<?xml version=1.0 encoding=utf-8 ?>
<Resources>
<ColorName=ColorPrimary>#008577</Color>
<ColorName=ColorPrimaryDark>#00574B</Color>
<ColorName=ColorAccent>#6646ee</Color>
<ColorName=ColorWhite>#fff</Color>
</Resources>.

1.2 Adding some filenames

<?xml Version=1.0 Encryption=utf-8? >

<Filename=Default_Rim>16dp</File>

<Dimentname=signable_padding>24dp</dimen>

<filename=text size>16sp</filename>

<filename=normal_padding>16dp>

<?xml version=1.0 encoding=utf-8?> <resources> <dimension name=default_margin>16dp</dimen> <dimension name=draw_margin>24dp</dimen> <dimension name=text_size>16sp</dimen> <dimension name=normal_margin>16dp</dimen> </resources>.

<?xml version=1.0 coding=utf-8 ?>
<Resources>
<File_Name=Standard_Ribbon>16dp</Dimension>
<File_Name=Strip_Character>24dp</Dimension>
<File_Name=Text_Size>16sp</Dimension>
<File_Name=Normal_Ribbon>16dp</Dimension>
</Resources>.

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

<Style name=floor_post>

<element_name=android:textSize>@dimen/text_size</item>

<item name=android:drawablePadding>@dimen/drawable_padding</item>

<element name=android: layout_width>0dp</item>

<position_name=android:position_height>envelope_content</article>

<position name=android:padding>@dimen/normal_padding</item>

<style_name=bottom_sheet_item> <item_name=android:textSize>@dimen/text_size</item> <item_name=android:drawablePadding>@dimen/drawable_padding</item> <item_name=android :layout_width>0dp</item> <element name=android:layout_height>wrap_content</item> <element name=android:padding>@dimen/normal_padding</item> </style>.

<style name=bottom_sheet_item>
<item name=android:textSize>@dimen/text_size</item>
<item name=android:drawablePadding>@dimen/drawable_padding</item>
<item name=android :layout_width>0dp</item>
<element_name=android:layout_height>wrap_content</item>
<element_name=android:padding>@dimen/normal_padding</item>
</style>

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.

<?xml Version=1.0 Encryption=utf-8? >

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=http://schemas.android.com/apk/res/android.

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

android:id=@+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

<androidx.constraintlayout.widget.ConstraintLayout

android: id=@+id/constraintLayout

android: layout_width=0dp

android: layout_height=wrap_content

android: background=@color/colorAccent

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:layout_constraintTop_toTopOf= higher

android:id=@+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:srcCompat=@drawable/user_image

android: id=@+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: textColor=@color/colorWhite

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStart_toEndOf=@+id/imageView

app:layout_constraintTop_toTopOf=@+id/imageView

android:id=@+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:text=loren.kushwaha@gmail.com

android: textColor=@color/colorWhite

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStart_toEndOf=@+id/imageView

app:layout_constraintTop_toBottomOf=@+id/textView

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.appcompat.widget.appCompatibleText view

android: layout_width=wrap_content

android: layout_height=wrap_content

android: layout_marginLeft=8dp

android: layout_marginStart=8dp

android: drawableTop=@drawable/ic_call

android: textColor=@color/colorAccent

app:layout_constraintEnd_toStartOf=@+id/button3

app:layout_restrictionHorizontal_preload=0.5

app:layout_constraintStartOf=higher

app:layout_constraintTop_toTopOf=@+id/button3

<androidx.appcompat.widget.appCompatibleText view

android: id=@+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:drawableTop=@drawable/ic_save

android: textColor=@color/colorAccent

app:layout_constraintEnd_toEndOf=higher

app:layout_restrictionHorizontal_preload=0.5

app:layout_constraintStart_toEndOf=@+id/button3

app:layout_constraintTop_toTopOf=@+id/button3

<androidx.appcompat.widget.appCompatibleText view

android: id=@+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: background=@android: colors/transparent

android:drawableTop=@drawable/ic_website

android: textColor=@color/colorAccent

app:layout_constraintEnd_toStartOf=@+id/button2

app:layout_restrictionHorizontal_preload=0.5

app:layout_constraintStart_toEndOf=@+id/button

app:layout_constraintTop_toBottomOf=@+id/constraintLayout

android:id=@+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:layout_constraintTop_toBottomOf=@+id/button3

android:id=@+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:layout_constraintTop_toBottomOf=@+id/textView3

android:id=@+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:layout_constraintTop_toBottomOf=@+id/textView4

android:id=@+id/textView6

android: layout_marginTop=8dp

android:text=@stringing/action_keep

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:layout_constraintTop_toBottomOf=@+id/textView5

style=@style/bottom_sheet_item

android:id=@+id/textView7

android: text=@string/action_inbox

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:layout_constraintTop_toBottomOf=@+id/textView6

style=@style/bottom_sheet_item

android:id=@+id/textView8

android: text=@string/action_hangout

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:layout_constraintTop_toBottomOf=@+id/textView7

style=@style/bottom_sheet_item

</androidx.constraintlayout.widget.ConstraintLayout>

<?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 android:id=@+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 > <androidx.constraintlayout.widget.ConstraintLayout android:id=@+id/constraintLayout android:layout_width=0dp android:layout_height=wrap_content android:background=@color/colorAccent app:layout_constraintEnd_toEndOf=parent app :layout_constraintStart_toStartOf=parent app:layout_constraintTopOf=parent > < android image display:id=@+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:srcCompat=@drawable/user_image /> <TextView android :id=@+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:textColor=@color/colorWhite android:textSize=18sp app:layout_constraintEnd_toEndOf=parent application :layout_constraintStart_toEndOf=@+id/imageView app:layout_constraintTop_toTopOf=@+id/imageView /> <TextView android:id=@+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:text=loren.kushwaha@gmail.com android:textColor=@color/color app:layout_constraintEnd_toEndOf=parent app:layout_constraintStart_toEndOf=@+id/imageView app:layout_constraintTop_toBottomOf=@+id/textView /> </androidx.constraintlayout.widget.constraintLayout> <androidx.appcompat.widget.AppCompatibleTextView android:id=@+id/knot android:layout_width=wrap_content android:layout_height=wrap_content android:layout_marginLeft=8dp android:layout_marginStart=8dp android :drawableTop=@drawable/ic_call android:text=Call android:textColor=@color/colorAccent app:layout_constraintEnd_toStartOf=@+id/button3 app:layout_constraintHorizontal_bias=0.5 app:layout_constraintStart_toStartOf=parent app:layout_constraintTop_toTopOf=@+id/button3 /> <androidx.appcompat.widget.AppCompatibleTextView android:id=@+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:drawableTop=@drawable/ic_save android:text=Save android:textColor=@color/colorAccent app:layout_constraintEnd_toEndOf=parent app:layout_constraintHorizontal_bias=0.5 app:layout_constraintStart_toEndOf=@+id/button3 app:layout_constraintTop_toTopOf=@+id/button3 /> <androidx.appcompat.widget.AppCompatibleTextView android:id=@+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 :background=@@@android:color/transparent android:drawableTop=@drawable/ic_website android:text=Website android:textColor=@color/colorAccent app:layout_constraintEnd_toStartOf=@+id/button2 app:layout_constraintHorizontal_bias=0.5 app:layout_constraintStart_toEndOf=@+id/knot app:layout_constraintTop_toBottomOf=@+id/constraintLayout /> <Biew android:id=@+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:layout_constraintTop_toBottomOf=@+id/button3 /> <TextView android :id=@+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:layout_constraintTop_toBottomOf=@+id/textView3 /> <view android:id=@+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:layout_constraintTop_toBottomOf=@+id/textView4 /> <TextView android :id=@+id/textView6 android:layout_marginTop=8dp android:text=@string/action_keep app:layout_constraintEnd_toEndOf=parent application layout_constraintStartOf=parent app:layout_constraintTop_toEndOf=@+id/textView5 style=@style/bottom_sheet_item /> <TextView android:id=@+id/textView7 android:text=@string/action_inbox app:layout_constraintEnd_toEndOf=parent app: layout_constraintStart_toStartOf=parent app :layout_constraintTop_toBottomOf=@+id/textView6 style=@style/bottom_sheet_item /> <TextView android:id=@+id/textView8 android:text=@string/action_hangout app :layout_constraintEnd_toEndOf=parent app:layout_constraintStartOf=parent app:layout_constraintTop_toBottomOf=@+id/textView7 style=@style/bottom_sheet_item /> </androidx.constraint layout.widget.constraintLayout>.

<?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
android:id=@+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
>
<androidx.constraintlayout.widget.ConstraintLayout
android:id=@+id/constraintLayout
android:layout_width=0dp
android:layout_height=wrap_content
android:background=@color/colorAccent
app :layout_constraintEnd_toEndOf=higher
app:layout_constraintStart_toStartOf=higher
app:layout_constraintTop_toTopOf=higher
>

<See imagesandroid:id=@+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:srcCompat=@drawable/user_image/><TextViewandroid :id=@+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 KushwahaandroidtextColor=@Color/ Colorandroid:textSize=18spapp:layout_constraintEnd_toEndOf=parentapp:layout_constraintStart_toEndOf=@+id/imageViewapp :layout_constraintTop_toTopOf=@+id/imageView/><TextViewandroid:id=@+id/textView2android:layout_width=0dpandroid:layout_height=wrap_contentandroid :layout_marginEnd=8dpandroid:layout_marginLeft=16dpandroid:layout_marginRight=8dpandroid:layout_marginStart=16dpandroid:layout_marginTop=2dpandroid:text=loren.kushwaha@gmail.comandroid:textColor=@color/colorWhiteapp:layout_constraintEnd_toEndOf=pairtapp:layout_constraintStart_toEndOf=@+id/imageViewapp:layout_constraintTop_toBottomOf=@+id/textView/></androidx.constraintlayout.widget.ConstraintLayout><androidx.appcompat.widget.AppCompatibleeTextViewandroid:id=@+id/buttonandroid:layout_wrap_contentandroid:layout_height=wrap_contentandroid:layout_marginLeft=8dpandroid:layout_marginStart=8dpandroid :drawableTop=@drawable/ic_callandroid:text=Callandroid:textColor=@color/colorAccentapp:layout_constraintEnd_toStartOf=@+id/button3app:layout_constraintHorizontal_bias=0.5app:layout_constraintStart_toStartOf=pairtapp:layout_constraintTop_toTopOf=@+id/button3/><androidx.appcompat.widget.AppCompatibleeTextViewandroid:id=@+id/button2android:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:layout_marginEnd=8dpandroid:layout_marginLeft=8dpandroid:layout_marginRight=8dpandroid :layout_marginStart=8dpandroid:drawableTop=@drawable/ic_saveandroid:text=Saveandroid:textColor=@color/colorAccentapp:layout_constraintEnd_toEndOf=pairtapp:layout_constraintHorizontal_bias=0.5app:layout_constraintStart_toEndOf=@+id/button3app:layout_constraintTop_toTopOf=@+id/button3/><androidx.appcompat.widget.AppCompatibleeTextViewandroid:id=@+id/button3android:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:layout_marginLeft=16dpandroid:layout_marginStart=16dpandroid:layout_marginTop=24dpandroid :background=@android:color/transparentandroid:drawableTop=@drawable/ic_websiteandroid:text=Websiteandroid:textColor=@color/olorAccentapp:layout_constraintEnd_toStartOf=@+id/button2app:layout_constraintHorizontal_bias=0.5app:layout_constraintStart_toEndOf=@+id/buttonapp:layout_constraintTop_toBottomOf=@+id/constraintLayout/><Viewandroid:id=@+id/textView3android:layout_width=0dpandroid:layout_height=1dpandroid :layout_marginTop=24dpandroid:background=#ededapp:layout_constraintEnd_toEndOf=pairtapp:layout_constraintStart_toStartOf=pairtapp:layout_constraintTop_toBottomOf=@+id/button3/><TextViewandroid :id=@+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:layout_constraintTop_toBottomOf=@+id/textView3/><Viewandroid :id=@+id/textView5android:layout_width=0dpandroid:layout_width=1dpandroid:layout_marginTop=8dpandroid:background=#ededapp:layout_constraintEnd_toEndOf=pairtapp :layout_constraintStart_toStartOf=pairtapp:layout_constraintTop_toBottomOf=@+id/textView4/><TextViewandroid:id=@+id/textView6android:layout_marginTop=8dpandroid :text=@string/action_keepapp:layout_constraintEnd_toEndOf=pairtapp:layout_constraintStart_toStartOf=pairtapp:layout_constraintTop_toBottomOf=@+id/textView5style=@style/bottom_sheet_items.

/>
<TextView
android:id=@+id/textView7
android:text=@string/action_inbox
app:layout_constraintEnd_toEndOf=parent
app :layout_constraintStart_toStartOf=parent
app:layout_constraintTop_toBottomOf=@+id/textView6
style=@style/bottom_sheet_item
/>
<TextView
android :id=@+id/textView8
android:text=@string/action_hangout
app:layout_constraintEnd_toEndOf= older
app:layout_constraintStart_toStartOf= older
app:layout_constraintTop_toBottomOf=@+id/textView7
style=@style/bottom_sheet_item
/>

</androidx.constraintlayout.widget.ConstraintLayout>

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.

<?xml Version=1.0 Encryption=utf-8? >

<androidx.coordinatorlayout.widget.coordinatorLayout

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

<androidx.constraintlayout.widget.ConstraintLayout

android: layout_width=match_parent

android: layout_height=match_parent

app:layout_behavior=@string/appbar_scrolling_view_behavior

android: id=@+id/textView10

android: layout_width=wrap_content

android: layout_height=wrap_content

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

android: textColor=@color/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:id=@+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:layout_constraintTop_toBottomOf=@+id/textViewState

android:id=@+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: textColor=@color/colorAccent

app:layout_constraintEnd_toEndOf=higher

app:layout_constraintStartOf=higher

app:layout_constraintTop_toBottomOf=@+id/textView10

tools: text=Basic sheet behavior status

</androidx.constraintlayout.widget.ConstraintLayout>

<including layout=@layout/bottom_sheet/>

</androidx.coordinatorlayout.widget.coordinatorLayout>

<?xml version=1.0 encoding=utf-8? > <androidx.coordinatorlayout.widget.coordinatorLayout 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 > <androidx.constraintlayout.widget.ConstraintLayout android:layout_width=match_parent android:layout_height=match_parent app:layout_behavior=@stringing/appbar_scrolling_view_behavior > <Text View android:id=@+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:textColor=@color/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 /> <button android:id=@+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=Toggle bottom sheet app:layout_constraintEnd_toEndOf=parent app:layout_constraintHorizontal_bias=0.497 app:layout_constraintStart_toStartOf=parent app:layout_constraintTop_toBottomOf=@+id/textViewState /> <TextView android:id=@+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:textColor=@color/colorAccent android:textSize=16sp android:textStyle=bold app:layout_constraintEnd_toEndOf=parent app:layout_constraintStart_toStartOf=parent app:layout_constraintTop_toBottomOf=@+id/textView10 tools:text=State of BottomSheet behavior /> </androidx.constraintlayout.widget.ConstraintLayout> <including layout=@layout/bottom_sheet/> </androidx.coordinatorlayout.widget.coordinatorLayout>.

<?xml version=1.0 encoding=utf-8? >
<androidx.coordinatorlayout.widget.coordinatorLayout
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
>.

<androidx.constraintlayout.widget.ConstraintLayout
androidx:layout_width=match_older
androidx:layout_height=match_older
app:layout_behavior=@string/appbar_scrolling_view_behavior
>.

<TextViewandroid:id=@+id/textView10android:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:gravity=centerandroid:text=This is an example of an application of BottomSheet behavior android:textColor=@color/colorPrimaryDarkandroid:textSize=16spapp:layout_constraintBottom_toBottomOf=parentapp:layout_constraintHorizontal_bias=0.0app:layout_constraintLeft_toLeftOf=übergeordnetapp:layout_constraintRight_toRightOf=übergeordnetapp:layout_constraintTop_toTopOf=übergeordnetapp:layout_constraintVertical_bias=0.054/><Smaakandroid:id=@+id/buttonToggleBottomSheetandroid:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:layout_marginEnd=8dpandroid:layout_marginLeft=8dpandroid:layout_marginRight=8dpandroid:layout_marginStart=8dpandroid:layout_marginStart=8dpandroid:layout_marginTop=16dpandroid:text=Wrap_constraintEnd_toEndOf=Pairtapp:layout_constraintHorizontal_bias=0.497app:layout_constraintStart_toStartOf=pairtapp:layout_constraintTop_toBottomOf=@+id/textViewState/><TextViewStateandroid:id=@+id/textViewStateandroid:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:layout_marginEnd=8dpandroid:layout_marginLeft=8dpandroid:layout_marginRight=8dpandroid:layout_marginStart=8dpandroid:layout_marginTop=16dpandroid:textColor=@color/colorAccentandroid:textSize=16spandroid:textStyle=boldapp:layout_constraintEnd_toEndOf=parent app :layout_constraintStart_toStartOf=parent app:layout_constraintTop_toBottomOf=@+id/textView10tools:text=State of BottomSheet behavior/></androidSize>.constraintlayout.widget.constraintLayout>.

<including layout=@layout/bottom_sheet/>

</androidx.coordinatorlayout.widget.coordinatorLayout>

4. Enter the behaviour of the bottom sheet in the activity.

After all the work we’ve done, let’s move on to the actual implementation of the resources.

Package com.android.bottom sheet ;

Import the android.os package;

import android.view

import android.widget.button ;

Import android.widget.textView ;

androidx.annotation.non-zero import;

Import androidx.appcompat.appCompatActivity ;

Import androidx.constraintlayout.widget.ConstraintLayout

com.google.android.material.bottomsheet.BottomsheetBehavior ;

the MainActivity public class expands AppCompatActivity {

TextSee textSee textSee textSee backgroundState ;

Button for shifting the bottom sheet;

Behavior under leaves Behavior under leaves ;

private static end line TAG = MainActivity ;

protected hole onCreate(Bundle storedInstanceState) {

create super.onCreate(savedInstanceState) ;

setContentView(R.layout.activity_main) ;

toggleBottomSheet = findViewById(R.id.buttonToggleBottomSheet) ;

textViewBottomSheetState = findViewById(R.id.textViewState) ;

// look at the bottom

ConstraintLayout bottomSheetLayout = findViewById(R.id.bottom_sheet) ;

// depending on the behaviour of the lower blade

bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout) ;

// Restore the reminder for changes

bottomSheetBehavior.setBottomSheetCallback(new bottomSheetBehavior.BottomSheetCallback() {)

Checking the public blank for StateateChanged (@NonNull View bottomSheet, int newState) {

the BottomSheetBehavior case. STATE_HIDDEN :

textViewBottomSheetState.setText(STATE HIDDEN) ;

Behavior at the bottom of the page. STATE_EXTENDED :

textViewBottomSheetState.setText(state extended) ;

// adjust the text of the shift key

switchBottomSheet.setText(Extend BottomSheet) ;

the BottomSheetBehavior.STATE_COLLAPSED case:

textViewBottomSheetState.setText(STATE COLLAPSED) ;

// minimized update button text

switchBottomSheet.setText(Collapse BottomSheet) ;

the BottomSheetBehavior.STATE_DRAGING case:

textViewBottomSheetState.setText(STATE DRAGGING) ;

the BottomSheetBehavior.STATE_SETTLING case:

textViewBottomSheetState.setText(STATE SETTLING) ;

Log.d(TAG, onStateChanged: + newState) ;

@ Detection of a public blank on the slide (@Non-zero view background sheet, slide offset from float) {

// put the listener in contact with the

switchBottomSheet.setOnClickListener(new view.OnClickListener() {)

@Define an audience blank image {.

if (bottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {

bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED) ;

switchBottomSheet.setText(Collapse BottomSheet) ;

bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLLAPSED) ;

switchBottomSheet.setText(Extend BottomSheet) ;

Import com.android.bottomsheet package; import android.os.bundle; import android.util.log; import android.view; import android.widget.Button; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.appCompatActivity; import androidx constraintlayout.widget.ConstraintLayout; com.google.android.android material.bottomsheet.import.BottomSheetBehavior; MainActivity public class extends AppCompatActivity {TextViewBottomSheetState; BottomSheetBehavior; closed static end string tag TAG = MainActivity; @Override protected cavities onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // bind UI toggleBottomSheet = findViewById(R.id..buttonToggleBottomSheet); textViewBottomSheetState = findViewById(R.id.)textViewState); // gives the layout of the bottomSheetLayout restrictions = findViewById(R.id.bottom_sheet); // specifies the behavior of the bottomSheetBehavior = BottomSheetBehavior.van(bottomSheetLayout); // set the callback to display the behavior of bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { switch (newState)) { case BottomSheetBehavior.STATE_HIDDEN: textViewBottomSheetState.setText(STATE HIDDEN); break; case BottomSheetBehavior.STATE_EXPANDED: textViewBottomSheetState.setText(STATE EXPANDED); // update text toggleBottomSheet.setText(Expand BottomSheet); break; case BottomSheetBehavior.STATE_COLLAPSED: textViewBottomSheetState.setText(STATE COLLAPSED); // refresh text button as minimized toggleBottomSheet.setText(Collapse BottomSheet); break; case BottomSheetBehavior.STATE_DRAGGING: textViewBottomSheetState.setText(STATE DRAGGING); break; case BottomSheetBehavior.STATE_SETTLING: textViewBottomSheetState.setText(STATE SETTLING); break; } Log.d(TAG, onStateChanged: + newState); } @ClickListener(@Nonzero view bottomSheet, SlidingFoilOffset) { })); // set the listener to theeBottomSheet.setOnClickListener(newView.OnClickListener() { @Offset public blank onClick(View-View) { if (bottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) { bottomSheetBehavior.STATE_EXPANDED) { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); } switchBottomSheet.setText(BottomSheetBehavior.STATE_EXPANDED collapse). otherwise { bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); } switchBottomSheet.setText(BottomSheet extend); } } }.

Package com.android.bottom sheet ;

Import android.os.bundle; import
android.util.log; import
android.view.view; import
android.widget.Button; import
android.widget.TextView; import
androidx.annotation.NonNull ;
import androidx.appcompat.appCompatActivity ;
import androidx.constraintlayout.widget.ConstraintLayout ;
import com.google.android.material.bottomsheet.BottomsheetBehavior ;

the MainActivity public class expands AppCompatActivity {

Text exampleBottom page previewStatus; switching between buttons; behaviour of bottom page ;

private static end line TAG = MainActivity ;

Overwrite
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.active_main);
// bind UI
toggleBottomSheet = findViewById(R.id.buttonToggleBottomSheet);
textViewBottomSheetState = findViewById(R.id.textViewState) ;

// gives the view of the lowest sheet
ConstraintLayout bottomSheetLayout = findViewById(R.id.bottom_sheet)

// enter the behaviour of the bottom plate
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout) ;

// set the callback for changesbottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {@Override public void onStateChanged(@NonNull View bottomSheet, int newState)) { switch(newState) {case BottomSheetBehavior.STATE_HIDDEN:textViewBottomSheetState.setText(STATE HIDDEN);break;case BottomSheetBehavior.STATE_EXPANDED:textViewBottomSheetState.setText(STATE EXPANDED);// update text switch buttoggleBottomSheet.setText(Expand BottomSheet);break;case BottomSheetBehavior.STATE_COLLAPSED:textViewBottomSheetState.setText(STATE COLLAPSED);// update texttoggleBottomSheet.setText(Collapse BottomSheet);break;case BottomSheetBehavior.STATE_DRAGGING:textViewBottomSheetState.setText(STATE DRAGGING);break;case BottomSheetBehavior.STATE_SETTLING:textViewBottomSheetState.setText(STATE SETTLING);break;}.

Log.d(TAG, onStateChanged: + newState);
}.

@ Detection of a public blank on the slide (@Non-zero view background sheet, slide offset from float) {

}});// set the listener to TheBottomSheet.setOnClickListener(new view.OnClickListener() {@Override public blank onClick(view) {if (bottomSheetBehavior.getState() != BottomSheetBehavior.STATE_EXPANDED) {bottomSheetBehavior.STATE_EXPANDED) {bottomSheetBehavior.STATE_EXPANDED) {bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED) {bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);toggleBottomSheet.setText(BottomSheetCollapse);}. otherwise {bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLLAPSED);toggleBottomSheet.setText(Expand BottomSheet);}}.

In the source file we still need to initialize the BottomSheetBehavior by adding a BottomSheet layout. I have also defined the change of state to understand the current state of the bottom sheet. The rest of the code speaks for itself.

Lower leaf condition

The bottom sheet consists mainly of 5 states…

  1. STATE_COLLAPSED – visible, but only indicates the height of the view This state is normally the resting position of the lower plate.
  2. STATE_ENLARGED – The lower blade is visible, the maximum height is not pulled or lowered.
  3. STATE_DRAGING – The user actively pulls the plate up or down.
  4. STATE_SETTLING – Fixed at a certain height after a drawing gesture.
  5. STATE_HIDDEN – no longer visible

Conclusion

In this function, we learned the introduction of the behaviour of the bottom sheet. I hope this will help you, then you help me by sharing this message with all your friends who are learning how to develop Android applications.

If you have any questions, please write your comments below. If you would like to integrate a UI/UX implementation into your Android project, please contact us.

 

 

 bottom sheet android kotlin,android bottom sheet rounded corners

You May Also Like