Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propper support to NavController #20

Open
ismaeldivita opened this issue Feb 4, 2020 · 16 comments
Open

Propper support to NavController #20

ismaeldivita opened this issue Feb 4, 2020 · 16 comments
Labels
enhancement New feature or request

Comments

@ismaeldivita
Copy link
Owner

No description provided.

@NIkhilbadveli
Copy link

NIkhilbadveli commented May 14, 2020

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
Copy link

it is not working for me

@shivjyotigarai
Copy link

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
Copy link

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

@shivjyotigarai
Copy link

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

@shivjyotigarai
Copy link

@NIkhilbadveli which itemId is referred above

@NIkhilbadveli
Copy link

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

Try it this way.

@shivjyotigarai
Copy link

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

Try it this way.

thx

@NIkhilbadveli
Copy link

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
Copy link

Suret1 commented Jan 22, 2021

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
Copy link

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

Thanks!

@OmarELRayes
Copy link

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

@NIkhilbadveli
Copy link

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
Copy link

Is there any update on Navigation support?

@saurabhthesuperhero
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

10 participants