简体   繁体   中英

For BottomNavigation the selected Item is not highlighted in android

I have bottomNavigation in my android app as shown below in picture. It works fine if I just click on home , cart and other bottomNavigation Items.

As you can see in picture that user can navigate to all categories in home . If I navigate to AllCategoriesFragment then in home item will be selected in bottomNavigation which is correct behavior. But if I go to cart and then click again on home then it shows AllCategoriesFragment which is also correct behavior but in BottomNavigation it doesnt highlight the home items, instead it keep cart item highlighted.

How I can get rid of this issue? Or how I can highlight the bottomNavigation selected item programmatically?

在此处输入图像描述

I did it programmatically like by getting activity reference inside fragment andd then getting navView from it and afterwards set the check state of the item to true

activity?.let {
            val navView = it.findViewById<BottomNavigationView>(R.id.nav_view)
            navView.menu.getItem(0).setChecked(true)
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM