diff --git a/lib/java/com/google/android/material/bottomnavigation/BottomNavigationMenuView.java b/lib/java/com/google/android/material/bottomnavigation/BottomNavigationMenuView.java index 1c3c28e2612..c9f986d74b9 100644 --- a/lib/java/com/google/android/material/bottomnavigation/BottomNavigationMenuView.java +++ b/lib/java/com/google/android/material/bottomnavigation/BottomNavigationMenuView.java @@ -77,7 +77,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { tempChildWidths.clear(); int parentHeight = MeasureSpec.getSize(heightMeasureSpec); - final int heightSpec = MeasureSpec.makeMeasureSpec(parentHeight, MeasureSpec.EXACTLY); + final int heightSpec = MeasureSpec.makeMeasureSpec(parentHeight, MeasureSpec.AT_MOST); if (isShifting(getLabelVisibilityMode(), visibleCount) && isItemHorizontalTranslationEnabled()) { @@ -131,6 +131,7 @@ && isItemHorizontalTranslationEnabled()) { } int totalWidth = 0; + int maxHeight = 0; for (int i = 0; i < totalCount; i++) { final View child = getChildAt(i); if (child.getVisibility() == GONE) { @@ -141,9 +142,10 @@ && isItemHorizontalTranslationEnabled()) { ViewGroup.LayoutParams params = child.getLayoutParams(); params.width = child.getMeasuredWidth(); totalWidth += child.getMeasuredWidth(); + maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); } - setMeasuredDimension(totalWidth, parentHeight); + setMeasuredDimension(totalWidth, Math.max(maxHeight, getSuggestedMinimumHeight())); } @Override diff --git a/lib/java/com/google/android/material/bottomnavigation/BottomNavigationView.java b/lib/java/com/google/android/material/bottomnavigation/BottomNavigationView.java index 61ba2e3c9cd..b11e4db5d22 100644 --- a/lib/java/com/google/android/material/bottomnavigation/BottomNavigationView.java +++ b/lib/java/com/google/android/material/bottomnavigation/BottomNavigationView.java @@ -19,7 +19,6 @@ import com.google.android.material.R; import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; -import static java.lang.Math.min; import android.content.Context; import android.os.Build.VERSION; @@ -168,6 +167,13 @@ public WindowInsetsCompat onApplyWindowInsets( protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int minHeightSpec = makeMinHeightSpec(heightMeasureSpec); super.onMeasure(widthMeasureSpec, minHeightSpec); + if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) { + setMeasuredDimension( + getMeasuredWidth(), + Math.max( + getMeasuredHeight(), + getSuggestedMinimumHeight() + getPaddingTop() + getPaddingBottom())); + } } private int makeMinHeightSpec(int measureSpec) { @@ -176,7 +182,7 @@ private int makeMinHeightSpec(int measureSpec) { minHeight += getPaddingTop() + getPaddingBottom(); return MeasureSpec.makeMeasureSpec( - min(MeasureSpec.getSize(measureSpec), minHeight), MeasureSpec.EXACTLY); + Math.max(MeasureSpec.getSize(measureSpec), minHeight), MeasureSpec.AT_MOST); } return measureSpec; diff --git a/lib/java/com/google/android/material/bottomnavigation/res/layout/design_bottom_navigation_item.xml b/lib/java/com/google/android/material/bottomnavigation/res/layout/design_bottom_navigation_item.xml index d64dd8d7876..591415f6685 100644 --- a/lib/java/com/google/android/material/bottomnavigation/res/layout/design_bottom_navigation_item.xml +++ b/lib/java/com/google/android/material/bottomnavigation/res/layout/design_bottom_navigation_item.xml @@ -15,53 +15,65 @@ ~ limitations under the License. --> - - - - + - - + + + + - - + - + android:visibility="invisible" /> + + diff --git a/lib/java/com/google/android/material/bottomnavigation/res/values/styles.xml b/lib/java/com/google/android/material/bottomnavigation/res/values/styles.xml index 887ccf46e96..bde27c71393 100644 --- a/lib/java/com/google/android/material/bottomnavigation/res/values/styles.xml +++ b/lib/java/com/google/android/material/bottomnavigation/res/values/styles.xml @@ -26,7 +26,8 @@ @dimen/design_bottom_navigation_icon_size auto @dimen/design_bottom_navigation_margin - @dimen/design_bottom_navigation_label_padding + 0dp + 1dp @null @dimen/design_bottom_navigation_height @@ -80,6 +81,7 @@ @dimen/m3_bottom_nav_min_height @style/ThemeOverlay.Material3.BottomNavigationView @style/ShapeAppearance.M3.Comp.NavigationBar.Container.Shape + @dimen/m3_navigation_item_active_indicator_label_padding