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

后端 未结 10 1363
面向向阳花
面向向阳花 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 19:53

    Your solution seems change the space between items

    There is my solution :

    "Just set color of clicked same as color of un-clicked."

    for example:

    private void changeMenuItemCheckedStateColor(BottomNavigationView bottomNavigationView, String checkedColorHex, String uncheckedColorHex) {
        int checkedColor = Color.parseColor(checkedColorHex);
        int uncheckedColor = Color.parseColor(uncheckedColorHex);
    
        int[][] states = new int[][] {
                new int[] {-android.R.attr.state_checked}, // unchecked
                new int[] {android.R.attr.state_checked}, // checked
    
        };
    
        int[] colors = new int[] {
                uncheckedColor,
                checkedColor
        };
    
        ColorStateList colorStateList = new ColorStateList(states, colors);
    
        bottomNavigationView.setItemTextColor(colorStateList);
        bottomNavigationView.setItemIconTintList(colorStateList);
    
    }
    

    if you want to un-check all items, you can

    changeMenuItemCheckedStateColor(mBottomNavigationView, "#999999", "#999999");
    

    if you want to restore the color setting, you can

    changeMenuItemCheckedStateColor(mBottomNavigationView, "FF743A", "999999");
    

提交回复
热议问题