The Android Developer Challenge is back! Submit your idea before December 2.

BottomAppBar

public class BottomAppBar
extends Toolbar implements CoordinatorLayout.AttachedBehavior

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ androidx.appcompat.widget.Toolbar
         ↳ com.google.android.material.bottomappbar.BottomAppBar


The Bottom App Bar is an extension of Toolbar that supports a shaped background that "cradles" an attached FloatingActionButton. A FAB is anchored to BottomAppBar by calling setAnchorId(int), or by setting app:layout_anchor on the FAB in xml.

Note: The Material Design Guidelines caution against using an ExtendedFloatingActionButton with a BottomAppBar, so there is limited support for that use case. ExtendedFloatingActionButton can be anchored to the BottomAppBar, but currently animations and the cutout are not supported.

There are two modes which determine where the FAB is shown relative to the BottomAppBar. FAB_ALIGNMENT_MODE_CENTER mode is the primary mode with the FAB is centered. FAB_ALIGNMENT_MODE_END is the secondary mode with the FAB on the side.

Do not use the android:background attribute or call BottomAppBar.setBackground because the BottomAppBar manages its background internally. Instead use app:backgroundTint.

To enable color theming for menu items you will also need to set the materialThemeOverlay attribute to a ThemeOverlay which sets the colorControlNormal attribute to the correct color. For example, if the background of the BottomAppBar is colorSurface, as it is in the default style, you should set materialThemeOverlay to @style/ThemeOverlay.MaterialComponents.BottomAppBar.Surface.

Summary

Nested classes

class BottomAppBar.Behavior

Behavior designed for use with BottomAppBar instances. 

@interface BottomAppBar.FabAlignmentMode

The fabAlignmentMode determines the horizontal positioning of the cradle and the FAB which can be centered or aligned to the end. 

@interface BottomAppBar.FabAnimationMode

The fabAnimationMode determines the animation used to move the FAB between different alignment modes. 

XML attributes

BottomAppBar_backgroundTint  
BottomAppBar_fabAlignmentMode  
BottomAppBar_fabAnimationMode  
BottomAppBar_fabCradleMargin  
BottomAppBar_fabCradleRoundedCornerRadius  
BottomAppBar_fabCradleVerticalOffset  
BottomAppBar_hideOnScroll  

Constants

int FAB_ALIGNMENT_MODE_CENTER

int FAB_ALIGNMENT_MODE_END

int FAB_ANIMATION_MODE_SCALE

int FAB_ANIMATION_MODE_SLIDE

Inherited constants

From class android.view.ViewGroup
From class android.view.View

Inherited fields

From class android.view.View

Public constructors

BottomAppBar(Context context)
BottomAppBar(Context context, AttributeSet attrs)
BottomAppBar(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

ColorStateList getBackgroundTint()
BottomAppBar.Behavior getBehavior()
float getCradleVerticalOffset()

Returns the vertical offset for the fab cutout.

int getFabAlignmentMode()

Returns the current fabAlignmentMode, either FAB_ALIGNMENT_MODE_CENTER or FAB_ALIGNMENT_MODE_END.

int getFabAnimationMode()

Returns the current fabAlignmentMode, either FAB_ANIMATION_MODE_SCALE or FAB_ANIMATION_MODE_SLIDE.

float getFabCradleMargin()

Returns the cradle margin for the fab cutout.

float getFabCradleRoundedCornerRadius()

Returns the rounded corner radius for the cutout.

boolean getHideOnScroll()

Returns true if the BottomAppBar should hide when a NestedScrollingChild is scrolled.

void performHide()

Animates the BottomAppBar so it hides off the screen.

void performShow()

Animates the BottomAppBar so it is shown on the screen.

void replaceMenu(int newMenu)

A convenience method to replace the contents of the BottomAppBar's menu.

void setBackgroundTint(ColorStateList backgroundTint)
void setCradleVerticalOffset(float verticalOffset)

Sets the vertical offset, in pixels, of the FloatingActionButton being cradled.

void setElevation(float elevation)
void setFabAlignmentMode(int fabAlignmentMode)

Sets the current fabAlignmentMode.

void setFabAnimationMode(int fabAnimationMode)

Sets the current fabAlignmentMode.

void setFabCradleMargin(float cradleMargin)

Sets the cradle margin for the fab cutout.

void setFabCradleRoundedCornerRadius(float roundedCornerRadius)

Sets the rounded corner radius for the fab cutout.

void setHideOnScroll(boolean hide)

Sets if the BottomAppBar should hide when a NestedScrollingChild is scrolled.

void setSubtitle(CharSequence subtitle)
void setTitle(CharSequence title)

Protected methods

void createFabDefaultXAnimation(int targetMode, List<Animator> animators)

Creates the default animation for moving a fab between alignment modes.

int getActionMenuViewTranslationX(ActionMenuView actionMenuView, int fabAlignmentMode, boolean fabAttached)

Returns the X translation to position the ActionMenuView.

void onAttachedToWindow()
void onLayout(boolean changed, int l, int t, int r, int b)
void onRestoreInstanceState(Parcelable state)
Parcelable onSaveInstanceState()

Inherited methods

From class androidx.appcompat.widget.Toolbar
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.view.ViewParent
From interface android.view.ViewManager
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface androidx.coordinatorlayout.widget.CoordinatorLayout.AttachedBehavior

XML attributes

BottomAppBar_backgroundTint

BottomAppBar_fabAlignmentMode

BottomAppBar_fabAnimationMode

BottomAppBar_fabCradleMargin

BottomAppBar_fabCradleRoundedCornerRadius

BottomAppBar_fabCradleVerticalOffset

BottomAppBar_hideOnScroll

Constants

FAB_ALIGNMENT_MODE_CENTER

int FAB_ALIGNMENT_MODE_CENTER

Constant Value: 0 (0x00000000)

FAB_ALIGNMENT_MODE_END

int FAB_ALIGNMENT_MODE_END

Constant Value: 1 (0x00000001)

FAB_ANIMATION_MODE_SCALE

int FAB_ANIMATION_MODE_SCALE

Constant Value: 0 (0x00000000)

FAB_ANIMATION_MODE_SLIDE

int FAB_ANIMATION_MODE_SLIDE

Constant Value: 1 (0x00000001)

Public constructors

BottomAppBar

BottomAppBar (Context context)

Parameters
context Context

BottomAppBar

BottomAppBar (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

BottomAppBar

BottomAppBar (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

getBackgroundTint

ColorStateList getBackgroundTint ()

Returns
ColorStateList

getBehavior

BottomAppBar.Behavior getBehavior ()

Returns
BottomAppBar.Behavior

getCradleVerticalOffset

float getCradleVerticalOffset ()

Returns the vertical offset for the fab cutout. An offset of 0 indicates the vertical center of the FloatingActionButton is positioned on the top edge.

Returns
float

getFabAlignmentMode

int getFabAlignmentMode ()

Returns the current fabAlignmentMode, either FAB_ALIGNMENT_MODE_CENTER or FAB_ALIGNMENT_MODE_END.

Returns
int

getFabAnimationMode

int getFabAnimationMode ()

Returns the current fabAlignmentMode, either FAB_ANIMATION_MODE_SCALE or FAB_ANIMATION_MODE_SLIDE.

Returns
int

getFabCradleMargin

float getFabCradleMargin ()

Returns the cradle margin for the fab cutout. This is the space between the fab and the cutout.

Returns
float

getFabCradleRoundedCornerRadius

float getFabCradleRoundedCornerRadius ()

Returns the rounded corner radius for the cutout. A value of 0 will be a sharp edge.

Returns
float

getHideOnScroll

boolean getHideOnScroll ()

Returns true if the BottomAppBar should hide when a NestedScrollingChild is scrolled. This is handled by BottomAppBar.Behavior.

Returns
boolean

performHide

void performHide ()

Animates the BottomAppBar so it hides off the screen.

performShow

void performShow ()

Animates the BottomAppBar so it is shown on the screen.

replaceMenu

void replaceMenu (int newMenu)

A convenience method to replace the contents of the BottomAppBar's menu.

Parameters
newMenu int: the desired new menu.

setBackgroundTint

void setBackgroundTint (ColorStateList backgroundTint)

Parameters
backgroundTint ColorStateList

setCradleVerticalOffset

void setCradleVerticalOffset (float verticalOffset)

Sets the vertical offset, in pixels, of the FloatingActionButton being cradled. An offset of 0 indicates the vertical center of the FloatingActionButton is positioned on the top edge.

Parameters
verticalOffset float

setElevation

void setElevation (float elevation)

Parameters
elevation float

setFabAlignmentMode

void setFabAlignmentMode (int fabAlignmentMode)

Sets the current fabAlignmentMode. An animated transition between current and desired modes will be played.

Parameters
fabAlignmentMode int: the desired fabAlignmentMode, either FAB_ALIGNMENT_MODE_CENTER or FAB_ALIGNMENT_MODE_END.

setFabAnimationMode

void setFabAnimationMode (int fabAnimationMode)

Sets the current fabAlignmentMode. Determines which animation will be played when the fab is animated from from one BottomAppBar.FabAlignmentMode to another.

Parameters
fabAnimationMode int: the desired fabAlignmentMode, either FAB_ALIGNMENT_MODE_CENTER or FAB_ALIGNMENT_MODE_END.

setFabCradleMargin

void setFabCradleMargin (float cradleMargin)

Sets the cradle margin for the fab cutout. This is the space between the fab and the cutout.

Parameters
cradleMargin float

setFabCradleRoundedCornerRadius

void setFabCradleRoundedCornerRadius (float roundedCornerRadius)

Sets the rounded corner radius for the fab cutout. A value of 0 will be a sharp edge.

Parameters
roundedCornerRadius float

setHideOnScroll

void setHideOnScroll (boolean hide)

Sets if the BottomAppBar should hide when a NestedScrollingChild is scrolled. This is handled by BottomAppBar.Behavior.

Parameters
hide boolean

setSubtitle

void setSubtitle (CharSequence subtitle)

Parameters
subtitle CharSequence

setTitle

void setTitle (CharSequence title)

Parameters
title CharSequence

Protected methods

createFabDefaultXAnimation

void createFabDefaultXAnimation (int targetMode, 
                List<Animator> animators)

Creates the default animation for moving a fab between alignment modes. Can be overridden by extending classes to create a custom animation. Animations that should be executed should be added to the animators list. The default animation defined here calls hide() and show() rather than using custom animations.

Parameters
targetMode int

animators List

getActionMenuViewTranslationX

int getActionMenuViewTranslationX (ActionMenuView actionMenuView, 
                int fabAlignmentMode, 
                boolean fabAttached)

Returns the X translation to position the ActionMenuView. When fabAlignmentMode is equal to FAB_ALIGNMENT_MODE_END and fabAttached is true, the ActionMenuView will be aligned to the end of the navigation icon, otherwise the ActionMenuView is not moved.

Parameters
actionMenuView ActionMenuView

fabAlignmentMode int

fabAttached boolean

Returns
int

onAttachedToWindow

void onAttachedToWindow ()

onLayout

void onLayout (boolean changed, 
                int l, 
                int t, 
                int r, 
                int b)

Parameters
changed boolean

l int

t int

r int

b int

onRestoreInstanceState

void onRestoreInstanceState (Parcelable state)

Parameters
state Parcelable

onSaveInstanceState

Parcelable onSaveInstanceState ()

Returns
Parcelable