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:[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
<androidx.constraintlayout.widget.ConstraintLayout
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
</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: [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
<androidx.appcompat.widget.appCompatibleText view
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
<androidx.appcompat.widget.appCompatibleText view
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
</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:[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 > <androidx.constraintlayout.widget.ConstraintLayout android:[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 /> <TextView android :[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 /> <TextView 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]/color app:layout_constraintEnd_toEndOf=parent app:[email protected]+id/imageView app:[email protected]+id/textView /> </androidx.constraintlayout.widget.constraintLayout> <androidx.appcompat.widget.AppCompatibleTextView android:[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 /> <androidx.appcompat.widget.AppCompatibleTextView 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: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 /> <androidx.appcompat.widget.AppCompatibleTextView 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]@@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 /> <Biew android:[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 /> <TextView 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_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 /> <view android:[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 /> <TextView android :[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 /> <TextView 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 /> <TextView android:[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 /> </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:[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
>
<androidx.constraintlayout.widget.ConstraintLayout
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
>
<See imagesandroid:[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/><TextViewandroid :[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/><TextViewandroid:[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/></androidx.constraintlayout.widget.ConstraintLayout><androidx.appcompat.widget.AppCompatibleeTextViewandroid:[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/><androidx.appcompat.widget.AppCompatibleeTextViewandroid:[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/><androidx.appcompat.widget.AppCompatibleeTextViewandroid:[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/><Viewandroid:[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/><TextViewandroid :[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/><Viewandroid :[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/><TextViewandroid:[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.
/>
<TextView
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
/>
<TextView
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
/>
</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:[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
</androidx.constraintlayout.widget.ConstraintLayout>
<including [email protected]/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:[email protected]/appbar_scrolling_view_behavior > <Text View android:[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 /> <button 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=Toggle bottom sheet app:layout_constraintEnd_toEndOf=parent app:layout_constraintHorizontal_bias=0.497 app:layout_constraintStart_toStartOf=parent app:[email protected]+id/textViewState /> <TextView 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 android:textSize=16sp android:textStyle=bold app:layout_constraintEnd_toEndOf=parent app:layout_constraintStart_toStartOf=parent app:[email protected]+id/textView10 tools:text=State of BottomSheet behavior /> </androidx.constraintlayout.widget.ConstraintLayout> <including [email protected]/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:[email protected]/appbar_scrolling_view_behavior
>.
<TextViewandroid:[email protected]+id/textView10android:layout_width=wrap_contentandroid:layout_height=wrap_contentandroid:gravity=centerandroid:text=This is an example of an application of BottomSheet behavior android:[email protected]/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:[email protected]+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:[email protected]+id/textViewState/><TextViewStateandroid:[email protected]+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:[email protected]/colorAccentandroid:textSize=16spandroid:textStyle=boldapp:layout_constraintEnd_toEndOf=parent app :layout_constraintStart_toStartOf=parent app:[email protected]+id/textView10tools:text=State of BottomSheet behavior/></androidSize>.constraintlayout.widget.constraintLayout>.
<including [email protected]/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…
- STATE_COLLAPSED – visible, but only indicates the height of the view This state is normally the resting position of the lower plate.
- STATE_ENLARGED – The lower blade is visible, the maximum height is not pulled or lowered.
- STATE_DRAGING – The user actively pulls the plate up or down.
- STATE_SETTLING – Fixed at a certain height after a drawing gesture.
- 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
