ismaeldivita / chip-navigation-bar

An android navigation bar widget
MIT License
890 stars 136 forks source link

Propper support to NavController #20

Open ismaeldivita opened 4 years ago

NIkhilbadveli commented 4 years ago

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.

jafar260698 commented 4 years ago

it is not working for me

shivjyotigarai commented 3 years ago

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

NIkhilbadveli commented 3 years ago

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

shivjyotigarai commented 3 years ago

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

shivjyotigarai commented 3 years ago

@NIkhilbadveli which itemId is referred above

NIkhilbadveli commented 3 years ago

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

Try it this way.

shivjyotigarai commented 3 years ago

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

Try it this way.

thx

NIkhilbadveli commented 3 years ago

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.

Suret1 commented 3 years ago

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

DevLuke67 commented 3 years ago

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

Thanks!

OmarELRayes commented 3 years ago

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

NIkhilbadveli commented 3 years ago

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

tolgaerbas1 commented 2 years ago

Is there any update on Navigation support?

saurabhthesuperhero commented 2 years ago

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.

alpeshSolanki7271 commented 2 years ago

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