Remove BottomNavigationView labels

前端 未结 8 585
一向
一向 2020-11-27 03:47

Google released new support library v25 with BottomNavigationView

is there any way to remove items labels ?

相关标签:
8条回答
  • 2020-11-27 04:47

    I hope I am not too late to the party here.

    But as of Design Support Library 28.0.0-alpha1 you can use the property

    app:labelVisibilityMode="unlabeled"
    

    you can use other values "auto", "labeled" and "selected" as well.

    0 讨论(0)
  • 2020-11-27 04:48

    I'd recommend to implement it by yourself as sanf0rd gave in his answer. But AppCompatImageView is not working for me. I've changed it to ImageView. And changed getChildAt to findViewById.

    Also I hide all labels of unselected items.

    private void centerMenuIcon() {
        BottomNavigationMenuView menuView = getBottomMenuView();
        if (menuView != null) {
            for (int i = 0; i < menuView.getChildCount(); i++) {
                BottomNavigationItemView menuItemView = (BottomNavigationItemView) menuView.getChildAt(i);
                TextView smallText = (TextView) menuItemView.findViewById(R.id.smallLabel);
                smallText.setVisibility(View.INVISIBLE);
                //TextView largeText = (TextView) menuItemView.findViewById(R.id.largeLabel);
                ImageView icon = (ImageView) menuItemView.findViewById(R.id.icon);
                FrameLayout.LayoutParams params = (LayoutParams) icon.getLayoutParams();
                params.gravity = Gravity.CENTER;
                menuItemView.setShiftingMode(true);
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题