BottomNavigationView - How to uncheck all MenuItems and keep Titles being displayed?

后端 未结 10 1337
面向向阳花
面向向阳花 2020-12-18 19:33

As I liked the design from BottomNavigationView I decided to implement a new Menu for my App with it, instead of just using simple buttons.

I took this

10条回答
  •  天涯浪人
    2020-12-18 20:11

    Thanks for your idea. I have implement it in my lib. I have a better way do it by reflect. So it won't show space.

    If you have interest. Click here : https://github.com/ittianyu/BottomNavigationViewEx

    private void initBottomViewAndLoadFragments(final BottomNavigationViewEx bnve) {
        bnve.enableAnimation(false);
        bnve.enableShiftingMode(false);
        bnve.enableItemShiftingMode(false);
    
        // use the unchecked color for first item
        bnve.setIconTintList(0, getResources().getColorStateList(R.color.bnv_unchecked_black));
        bnve.setTextTintList(0, getResources().getColorStateList(R.color.bnv_unchecked_black));
    
        bnve.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
    
            private boolean firstClick = true;
            private int lastItemId = -1;
    
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                // restore the color when click
                if (firstClick) {
                    firstClick = false;
                    bnve.setIconTintList(0, getResources().getColorStateList(R.color.selector_bnv));
                    bnve.setTextTintList(0, getResources().getColorStateList(R.color.selector_bnv));
                }
    
                if (firstClick || lastItemId == -1 || lastItemId != item.getItemId()) {
                    lastItemId = item.getItemId();
                } else {
                    return false;
                }
    
                // do stuff
                return fillContent(item.getItemId());
            }
        });
    }
    

    -- res/color/selector_bnv.xml

    
    
        
        
    
    

    -- res/values/colors.xml

    @android:color/white
    @android:color/black
    

提交回复
热议问题