Open ismaeldivita opened 4 years ago
it is not working for me
I pulled off a small trick to do this. You need to do it this way:
- Create a bottomnavigation view in xml file like this and set its visibility to "Gone".
<com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottomNav" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone" app:menu="@menu/bottom_menu" />
- And then do it like this in your activity file.
val navController: NavController = Navigation.findNavController(this, R.id.fragment) val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottomNav) val chipNavigationBar: ChipNavigationBar = findViewById(R.id.chip_nav) chipNavigationBar.setOnItemSelectedListener { itemId -> bottomNavigationView.selectedItemId = itemId } NavigationUI.setupWithNavController(bottomNavigationView, navController)
What I'm doing is making android think that there's a bottomnavigation that's changing it's state whenever we click on our chip navigator here.
Try this and let me know if it solves your problem.
@NIkhilbadveli can u plz write the code in activity file (2) in java plz
It's pretty straightforward... maybe try online for converting kotlin code to java
Just facing issue with this line...chipNavigationBar.setOnItemSelectedListener { itemId -> bottomNavigationView.selectedItemId = itemId }
. @NIkhilbadveli
@NIkhilbadveli which itemId is referred above
.setOnItemSelectedListener(new ChipNavigationBar.OnItemSelectedListener() { @Override public void onItemSelected(int id) { // TODO } });
Try it this way.
.setOnItemSelectedListener(new ChipNavigationBar.OnItemSelectedListener() { @override public void onItemSelected(int id) { // TODO } });
Try it this way.
thx
itemId is the id of the selection in chip navigation bar. I'm taking that and passing it to bottomnavigationview, which actually does the navigation.
I pulled off a small trick to do this. You need to do it this way:
- Create a bottomnavigation view in xml file like this and set its visibility to "Gone".
<com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottomNav" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone" app:menu="@menu/bottom_menu" />
- And then do it like this in your activity file.
val navController: NavController = Navigation.findNavController(this, R.id.fragment) val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottomNav) val chipNavigationBar: ChipNavigationBar = findViewById(R.id.chip_nav) chipNavigationBar.setOnItemSelectedListener { itemId -> bottomNavigationView.selectedItemId = itemId } NavigationUI.setupWithNavController(bottomNavigationView, navController)
What I'm doing is making android think that there's a bottomnavigation that's changing it's state whenever we click on our chip navigator here.
Try this and let me know if it solves your problem.
hi. should i do this? it didn't work for me too. I will be glad if you help me
Just facing issue with this line...
chipNavigationBar.setOnItemSelectedListener { itemId -> bottomNavigationView.selectedItemId = itemId }
. @NIkhilbadveli
Thanks!
but how do you handle "back" with it , chip navigation view doesn't update its items
If you set the chip navigation item whenever there's a navigation change, then it should work. //Changing chip navigation selection on change navController.addOnDestinationChangedListener { _, destination, _ -> chipNavigationBar.setItemSelected(destination.id) }
Is there any update on Navigation support?
So
If you set the chip navigation item whenever there's a navigation change, then it should work.
//Changing chip navigation selection on change navController.addOnDestinationChangedListener { _, destination, _ -> chipNavigationBar.setItemSelected(destination.id) }
OMG thanks so all the above worked properly as you mentioned.
when I back press at last position ..fragment changed but icon not change..
I pulled off a small trick to do this. You need to do it this way:
<com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottomNav" android:layout_width="match_parent" android:layout_height="wrap_content" android:visibility="gone" app:menu="@menu/bottom_menu" />
val navController: NavController = Navigation.findNavController(this, R.id.fragment) val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottomNav) val chipNavigationBar: ChipNavigationBar = findViewById(R.id.chip_nav) chipNavigationBar.setOnItemSelectedListener { itemId -> bottomNavigationView.selectedItemId = itemId } NavigationUI.setupWithNavController(bottomNavigationView, navController)
What I'm doing is making android think that there's a bottomnavigation that's changing it's state whenever we click on our chip navigator here.
Try this and let me know if it solves your problem.