BottomAppBar

public class BottomAppBar
extends Toolbar implements CoordinatorLayout.AttachedBehavior

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.support.v7.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.

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. 

XML attributes

BottomAppBar_backgroundTint  
BottomAppBar_fabAlignmentMode  
BottomAppBar_fabCradleMargin  
BottomAppBar_fabCradleRoundedCornerRadius  
BottomAppBar_fabCradleVerticalOffset  
BottomAppBar_hideOnScroll  

Constants

int FAB_ALIGNMENT_MODE_CENTER

int FAB_ALIGNMENT_MODE_END

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()
Behavior<BottomAppBar> 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.

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 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 setFabAlignmentMode(int fabAlignmentMode)

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 onLayout(boolean changed, int l, int t, int r, int b)
void onRestoreInstanceState(Parcelable state)
Parcelable onSaveInstanceState()

Inherited methods

From class android.support.v7.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 android.support.design.widget.CoordinatorLayout.AttachedBehavior

XML attributes

BottomAppBar_backgroundTint

BottomAppBar_fabAlignmentMode

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)

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

Behavior<BottomAppBar> getBehavior ()

Returns
Behavior<BottomAppBar>

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

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

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

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.

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

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