Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

BottomAppBar

public class BottomAppBar
extends Toolbar

java.lang.Object
   ↳ 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 ERROR(/CoordinatorLayout.LayoutParams#setAnchorId(int)), or by setting app:layout_anchor on the FAB in xml.

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.

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. 

Constants

int FAB_ALIGNMENT_MODE_CENTER

int FAB_ALIGNMENT_MODE_END

Public constructors

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

Public methods

float getCradleVerticalOffset()

Returns the vertical offset for the cradle.

int getFabAlignmentMode()

Returns the current fabAlignmentMode, either FAB_ALIGNMENT_MODE_CENTER or FAB_ALIGNMENT_MODE_END.

boolean getHideOnScroll()

Returns true if the BottomAppBar should hide when a ERROR(/android.support.v4.view.NestedScrollingChild) is scrolled.

boolean isFabAttached()

Returns true if the FAB should be cradled, false otherwise.

void replaceMenu(int newMenu)

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

void setCradleVerticalOffset(int verticalOffset)

Sets the cradle vertical offset

void setFabAlignmentMode(int fabAlignmentMode)

Sets the current fabAlignmentMode.

void setFabAttached(boolean attached)

Sets the current state which determines if the FAB is cradled or not.

void setHideOnScroll(boolean hide)

Sets if the BottomAppBar should hide when a ERROR(/android.support.v4.view.NestedScrollingChild) is scrolled.

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

Protected methods

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

Inherited methods

From class java.lang.Object

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)

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

getCradleVerticalOffset

float getCradleVerticalOffset ()

Returns the vertical offset for the cradle.

Returns
float

getFabAlignmentMode

int getFabAlignmentMode ()

Returns the current fabAlignmentMode, either FAB_ALIGNMENT_MODE_CENTER or FAB_ALIGNMENT_MODE_END.

Returns
int

getHideOnScroll

boolean getHideOnScroll ()

Returns true if the BottomAppBar should hide when a ERROR(/android.support.v4.view.NestedScrollingChild) is scrolled. This is handled by BottomAppBar.Behavior.

Returns
boolean

isFabAttached

boolean isFabAttached ()

Returns true if the FAB should be cradled, false otherwise.

Returns
boolean

replaceMenu

void replaceMenu (int newMenu)

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

Parameters
newMenu int: the desired new menu.

setCradleVerticalOffset

void setCradleVerticalOffset (int verticalOffset)

Sets the cradle vertical offset

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.

setFabAttached

void setFabAttached (boolean attached)

Sets the current state which determines if the FAB is cradled or not.

Parameters
attached boolean

setHideOnScroll

void setHideOnScroll (boolean hide)

Sets if the BottomAppBar should hide when a ERROR(/android.support.v4.view.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

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