@@ -494,6 +494,9 @@ private static void updateFabAnchorGravity(BottomAppBar bar, View fab) {
494494 if (bar .fabAnchorMode == FAB_ANCHOR_MODE_CRADLE ) {
495495 fabLayoutParams .anchorGravity |= Gravity .TOP ;
496496 }
497+ if (bar .fabAnchorMode == FAB_ANCHOR_MODE_EMBED ) {
498+ fabLayoutParams .anchorGravity |= Gravity .BOTTOM ;
499+ }
497500 }
498501
499502 /**
@@ -1138,7 +1141,15 @@ protected int getActionMenuViewTranslationX(
11381141
11391142 int actionMenuViewStart = isRtl ? actionMenuView .getRight () : actionMenuView .getLeft ();
11401143 int systemStartInset = isRtl ? rightInset : -leftInset ;
1141- int end = actionMenuViewStart + systemStartInset ;
1144+ // If there's no navigation icon, we want to add margin since we are translating the menu items
1145+ // to the start.
1146+ int marginStart = 0 ;
1147+ if (getNavigationIcon () == null ) {
1148+ int horizontalMargin =
1149+ getResources ().getDimensionPixelOffset (R .dimen .m3_bottomappbar_horizontal_padding );
1150+ marginStart = isRtl ? horizontalMargin : -horizontalMargin ;
1151+ }
1152+ int end = actionMenuViewStart + systemStartInset + marginStart ;
11421153
11431154 return toolbarLeftContentEnd - end ;
11441155 }
@@ -1300,26 +1311,32 @@ public void onLayoutChange(
13001311 BottomAppBar child = viewRef .get ();
13011312
13021313 // If the child BAB no longer exists, remove the listener.
1303- if (child == null || !(v instanceof FloatingActionButton )) {
1314+ if (child == null
1315+ || !(v instanceof FloatingActionButton
1316+ || v instanceof ExtendedFloatingActionButton )) {
13041317 v .removeOnLayoutChangeListener (this );
13051318 return ;
13061319 }
13071320
1308- FloatingActionButton fab = ((FloatingActionButton ) v );
1321+ int height = v .getHeight ();
1322+ if (v instanceof FloatingActionButton ) {
1323+ FloatingActionButton fab = ((FloatingActionButton ) v );
13091324
1310- fab .getMeasuredContentRect (fabContentRect );
1311- int height = fabContentRect .height ();
1325+ fab .getMeasuredContentRect (fabContentRect );
13121326
1313- // Set the cutout diameter based on the height of the fab.
1314- child .setFabDiameter (height );
1327+ height = fabContentRect .height ();
13151328
1316- // Assume symmetrical corners
1317- float cornerSize =
1318- fab .getShapeAppearanceModel ()
1319- .getTopLeftCornerSize ()
1320- .getCornerSize (new RectF (fabContentRect ));
1329+ // Set the cutout diameter based on the height of the fab.
1330+ child .setFabDiameter (height );
13211331
1322- child .setFabCornerSize (cornerSize );
1332+ // Assume symmetrical corners
1333+ float cornerSize =
1334+ fab .getShapeAppearanceModel ()
1335+ .getTopLeftCornerSize ()
1336+ .getCornerSize (new RectF (fabContentRect ));
1337+
1338+ child .setFabCornerSize (cornerSize );
1339+ }
13231340
13241341 CoordinatorLayout .LayoutParams fabLayoutParams =
13251342 (CoordinatorLayout .LayoutParams ) v .getLayoutParams ();
@@ -1329,19 +1346,27 @@ public void onLayoutChange(
13291346 if (originalBottomMargin == 0 ) {
13301347 // Extra padding is added for the fake shadow on API < 21. Ensure we don't add too
13311348 // much space by removing that extra padding.
1332- int bottomShadowPadding = (fab .getMeasuredHeight () - height ) / 2 ;
1349+ int bottomShadowPadding = (v .getMeasuredHeight () - height ) / 2 ;
13331350 int bottomMargin = 0 ;
13341351 if (child .fabAnchorMode == FAB_ANCHOR_MODE_CRADLE ) {
1335- bottomMargin = child
1336- .getResources ()
1337- .getDimensionPixelOffset (R .dimen .mtrl_bottomappbar_fab_bottom_margin );
1352+ bottomMargin =
1353+ child
1354+ .getResources ()
1355+ .getDimensionPixelOffset (R .dimen .mtrl_bottomappbar_fab_bottom_margin );
1356+ // Should be moved above the bottom insets with space ignoring any shadow padding.
1357+ int minBottomMargin = bottomMargin - bottomShadowPadding ;
1358+ fabLayoutParams .bottomMargin = child .getBottomInset () + minBottomMargin ;
1359+ } else if (child .fabAnchorMode == FAB_ANCHOR_MODE_EMBED ) {
1360+ // We want to add a margin of half of the height of the bottom app bar, minus half
1361+ // the height of the fab to the bottom of the fab. Since the height of the bottom
1362+ // app bar does not include the bottom inset, must add it to the height.
1363+ fabLayoutParams .bottomMargin =
1364+ (child .getMeasuredHeight () + child .getBottomInset () - v .getMeasuredHeight ())
1365+ / 2 ;
13381366 }
1339- // Should be moved above the bottom insets with space ignoring any shadow padding.
1340- int minBottomMargin = bottomMargin - bottomShadowPadding ;
1341- fabLayoutParams .bottomMargin = child .getBottomInset () + minBottomMargin ;
13421367 fabLayoutParams .leftMargin = child .getLeftInset ();
13431368 fabLayoutParams .rightMargin = child .getRightInset ();
1344- boolean isRtl = ViewUtils .isLayoutRtl (fab );
1369+ boolean isRtl = ViewUtils .isLayoutRtl (v );
13451370 if (isRtl ) {
13461371 fabLayoutParams .leftMargin += child .fabOffsetEndMode ;
13471372 } else {
@@ -1394,12 +1419,11 @@ public boolean onLayoutChild(
13941419 fab .setHideMotionSpecResource (R .animator .mtrl_fab_hide_motion_spec );
13951420 }
13961421
1397- // Always update the BAB if the fab is laid out.
1398- fab .addOnLayoutChangeListener (fabLayoutListener );
1399-
14001422 // Ensure the FAB is correctly linked to this BAB so the animations can run correctly
14011423 child .addFabAnimationListeners (fab );
14021424 }
1425+ // Always update the BAB if the fab/efab is laid out.
1426+ dependentView .addOnLayoutChangeListener (fabLayoutListener );
14031427
14041428 // Move the fab to the correct position
14051429 child .setCutoutStateAndTranslateFab ();
0 commit comments