Resize the BottomNavigationView Icon

I experimented with the new BottomNavigationView and tried to customize it.

So far, I have managed to change the height and margins using below:

<dimen name="design_bottom_navigation_height" tools:override="true">75dp</dimen>
<dimen name="design_bottom_navigation_margin" tools:override="true">5dp</dimen>

I want to increase the size of the icons.

How can I do that?

Compile version: com.android.support:design:25.0.1

+4
source share
1 answer

The icon size is hardcoded to 24dp in the layout of the elements (see design_bottom_navigation_item.xml ) and can be changed programmatically:

BottomNavigationView bottomNavigationView = (BottomNavigationView) configurationActivity.findViewById(R.id.bottom_navigation_view);
BottomNavigationMenuView menuView = (BottomNavigationMenuView) bottomNavigationView.getChildAt(0);
for (int i = 0; i < menuView.getChildCount(); i++) {
    final View iconView = menuView.getChildAt(i).findViewById(android.support.design.R.id.icon);
    final ViewGroup.LayoutParams layoutParams = iconView.getLayoutParams();
    final DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
    layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, displayMetrics);
    layoutParams.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, displayMetrics);
    iconView.setLayoutParams(layoutParams);
}
+16
source

Source: https://habr.com/ru/post/1666058/


All Articles