chip-navigation-bar icon indicating copy to clipboard operation
chip-navigation-bar copied to clipboard

Propper support to NavController

Open ismaeldivita opened this issue 4 years ago • 16 comments

ismaeldivita avatar Feb 04 '20 10:02 ismaeldivita

I pulled off a small trick to do this. You need to do it this way:

  1. 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" />
  2. 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 avatar May 14 '20 11:05 NIkhilbadveli

it is not working for me

jafar260698 avatar Aug 05 '20 18:08 jafar260698

I pulled off a small trick to do this. You need to do it this way:

  1. 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" />
  2. 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

shivjyotigarai avatar Dec 23 '20 09:12 shivjyotigarai

It's pretty straightforward... maybe try online for converting kotlin code to java

NIkhilbadveli avatar Dec 23 '20 09:12 NIkhilbadveli

Just facing issue with this line...chipNavigationBar.setOnItemSelectedListener { itemId -> bottomNavigationView.selectedItemId = itemId }. @NIkhilbadveli

shivjyotigarai avatar Dec 23 '20 09:12 shivjyotigarai

@NIkhilbadveli which itemId is referred above

shivjyotigarai avatar Dec 23 '20 09:12 shivjyotigarai

.setOnItemSelectedListener(new ChipNavigationBar.OnItemSelectedListener() { @Override public void onItemSelected(int id) { // TODO } });

Try it this way.

NIkhilbadveli avatar Dec 23 '20 09:12 NIkhilbadveli

.setOnItemSelectedListener(new ChipNavigationBar.OnItemSelectedListener() { @override public void onItemSelected(int id) { // TODO } });

Try it this way.

thx

shivjyotigarai avatar Dec 23 '20 09:12 shivjyotigarai

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.

NIkhilbadveli avatar Dec 23 '20 09:12 NIkhilbadveli

I pulled off a small trick to do this. You need to do it this way:

  1. 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" />
  2. 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

Screenshot 2021-01-22 185505

2

Suret1 avatar Jan 22 '21 14:01 Suret1

Just facing issue with this line...chipNavigationBar.setOnItemSelectedListener { itemId -> bottomNavigationView.selectedItemId = itemId }. @NIkhilbadveli

Thanks!

DevLuke67 avatar Feb 16 '21 00:02 DevLuke67

but how do you handle "back" with it , chip navigation view doesn't update its items

OmarELRayes avatar Sep 15 '21 15:09 OmarELRayes

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) }

NIkhilbadveli avatar Sep 17 '21 08:09 NIkhilbadveli

Is there any update on Navigation support?

tolgaerbas1 avatar Mar 09 '22 19:03 tolgaerbas1

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.

saurabhthesuperhero avatar Sep 29 '22 20:09 saurabhthesuperhero

when I back press at last position ..fragment changed but icon not change..

alpeshSolanki7271 avatar Oct 15 '22 05:10 alpeshSolanki7271