Read now

BottomAppBar with Floating action button in Android

BottomAppBar with Floating action button in Android :

In this article, we are going to learn how to use the BottomAppBar with Floating action button in Android.

Bottom App Bar :

Android’s bottom app bar component APIs provide support for the navigation icon, action items, overflow menu, and more for informing the user as to what each action performs. While optional, their use is strongly encouraged.

Content descriptions

When using icons for navigation icons, action items, and other elements of bottom app bars, you should set a content description on them so that screen readers like TalkBack are able to announce their purpose or action, if any.

For an overall content description of the bottom app bar, set and android:contentDescription or use the setContentDescription method on the BottomAppBar.

For the navigation icon, this can be achieved via the app:navigationContentDescription attribute or setNavigationContentDescription method.

Bottom app bars provide access to a bottom navigation drawer and up to four actions, including the floating action button.

BottomAppBar can be included in your screen layout like so :

Note: Please make use that you are using the “Theme.MaterialComponents.DayNight.NoActionBar” in you app AppTheme like below. If you are not using the MaterialComponents theme then you can not use the BottomoAppBar.

styles.xml :

Anchoring a Floating Action Bar :

FloatingActionButton can be anchored to a BottomAppBar. We are using “layout_anchor” to attach the  FAB to the BottomAppBar. You just have pass the id at which you want to anchor your FAB.

In my case, I have chosen the default properties.  “cradled” within a cutout. This is the default behavior.

In order to implement this, the FAB also needs to be within the parent CoordinatorLayout :

Here we achieve the BottomAppBar with Floating action button in Android.

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close