BottomNavigationView3個項以上不顯示文字的問題


 

1、xml

<!--app:labelVisibilityMode="labeled"  -->
<com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottom_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@android:color/white"
            app:labelVisibilityMode="labeled"  
            app:layout_behavior=".utils.BottomNavigationBehavior"
            design:menu="@menu/tab_menu" />

2、java

//onCreate中
viewDataBinding.bottomView.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_LABELED);

3、底部組建切換

        viewDataBinding.bottomView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
                Fragment fragment = null;
                switch (menuItem.getItemId()) {
                    case R.id.menu:
                          fragment = mHomeFragment;
                          break;
                }
                if (getSupportActionBar() != null) {
                    getSupportActionBar().setTitle(menuItem.getTitle());//如果toolbar不為空,將title換掉
                }
                switchFragment(fromFragment, fragment);
                fromFragment = fragment;
                return true;           //如果返回為false,則切換底部按鈕顏色不會切換
            }
        });

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM