to anyone whose app crashes when you do this. change the navhost package tag in activity_main.xml to just fragment or your app will crash. thank you so much to the poster of this video. you were very clear and easy to understand. it was just that little detail in the tag that was driving me crazy cuz my app kept crashing. lol. hope this helps someone!
@@sayanadhikari3220 sorry, but rn I'm on a deadline of something, 😭 and also I forgot the exact location of the project conatining the code pertaining that problem
I like this video, not because it's perfect or anything, but it shows someone using android studio and not just writing xml like everyone and their mothers.
Holy shit, your content is Gold! I thought I was becoming stupid due to listening to those unclear tutorials, but yours was clear and spot on. Thanks man!
Also the java code for the AppBarConfiguartion is; AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.firstFragment, R.id.secondFragment, R.id.thirdFragment).build(); NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
4:21 I liked how he selected all (Ctrl + A) then pressed the magic key, then all took his place like a good solders :) I've tried some keys and almost nuke my entire project, then I became like a good solder who must do boring stuff to my project :\
question :- if I go from second fragment to third fragment then press back its back to Fragment One(home start destination ) but must be back to second Fragment .why?
great videos !!, Please make video about handling the backstack, its so difficult for me.., this is my cases, here the flow of navigation graph : 1. A-B-C 2. D-B-F The question is, how the B fragment knows, which fragment that called them, from A or D, i mean how to handle onBackpress, im glad if u have the solution, thanks dude!
Thanks so much sir, it's working perfeclty. The only problem that i had was: Kotlin recreted a "Fragment" intead "fragment", and you didnt show us that we needed to create an id on fragment, in the line: 25 of "activity_main". apartfrom that, everything is working. Thanks
@@theworldminusraphtheninjat4378 This is a fairy simple project I discontinued. I used that technique in this app. Take a look: github.com/Re1r0/StudyAssistant Edit: I used a custom library because it looks good. But the same can be achieved using Google's de facto bottom navigation view.
I was stuck with the problem of switching the fragments when pressing the bottom navbar items but when i set the same id of fragments in my_nav and items in bottom_nav (menu) it runs succesfully.
If this code don't work. Perhaps this will help you: val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment) as NavHostFragment val navController = navHostFragment.navController findViewById(R.id.bottomNavigationView) .setupWithNavController(navController)
I have a problem with this: I have created the fragments, but i have a google maps activity, that i want to add in the navbar. I put it in my:nav.xml and detects that is an activity. When i run my app i can navigate normaly, but when i press in Maps button it crashes. Any solution to implements a normal activity?
It is good tutorial. I did all but when I click the icons, the app goes wrong and disappear from the emulator. And when I remove the fragments, I can see the icons but they don't listen at all. And the other thing is, I couldn't get the titles with the icons. Why? Android Studio couldn't detect me where I missed it. Please help me.
@@StevdzaSan Hi I just want to ask you if you please this question: I created a button in the home fragment that takes me to a fourth fragment (not included in the navigation bar), and when navigating to another fragment from the bar, and then clicking the home button from the navigation bar, that 4th fragment is still, I want to return to the home.If u can suggest a way.Thanks!
Hello, I have a question, how can I update a values other fragments, for example i have an app that can save some tasks, so i have one fragment to show tasks and another one to set and save tasks, but fragment pages do not refreshed or reload so it problematic to me, to show the added or updated data instead of just switching fragment I am turning off the app and turn un, so how can I solve it?
It was a nice video but one thing I'd like to bring to your notice is that I didn't get to use app bar configuration object. Action bar's title was changing with just a method which is set up action bar with nav controller and with just one parameter navController. So why did you make that extra instance of app bar configuration?
why my fragment didnt become class, even though they are class. i already follow all instruction rewacth video 3x. pretty sure im have same code with u. but the app crashed...
We have 3 top-level destinations (first fragment, second ... and third), when I click BottomNavigationView to navigete to second or third fragment, then press the back button, it will always come back to first fragment. Only when I'm in first fragment, press the back button can exit the activity. How to make exit activity when I cpress back button no matter what fragment I'm in?
Hi there i used your tutorial and it works perfectly but im facing the issue that it seems to override my start activity which is my login activity and launches this bottom navigation activity first each time. Is there any fix to this?
Is this a Java tutorial or Kotlin? and plz let us know ahead of time if you will be working with Kotlin or Java i like to stay consistent...Anyways great job sir thanks
In Java i tried using AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.firstFragment, R.id.secondFragment, R.id.thirdFragment).build(); and NavigationUI.setupWithNavController(appBarConfiguration); to update the top app bar. However, android is telling me "Cannot resolve method setUpWithNavController(appBarConfiguration)" does anyone know how to resolve this?
@@StevdzaSan It doesnt change the title when the app navigates to a new fragment. Please look into it. even your code that you ask to refer to doesn't change it
Here it is: Set topLevelDestinations = new HashSet(); topLevelDestinations.add(R.id.firstFragment); topLevelDestinations.add(R.id.secondFragment); topLevelDestinations.add(R.id.thirdFragment); AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(topLevelDestinations).build(); NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
@@sambhusbabu So what I did was not use this navigation component library, I chose to add fragments and hide/show the other fragment based on user interaction, thus saving the states
Can someone help me? I have the exact same code as the video with, the only difference is that a fragment from a nav_graph to an another activity (HomeActivity) with another (surely in the future) nav_graph navigation. The problem is that all navigation function well but the AppBar and the BottomNavigationView doesn't display at the activity and seems like it only renders the pure fragment with the text. can someone help me?
Hi nice tutorial. How can I add gridView in Home Fragment ? I can create gridView other app in mainActivity bu I can't open gridView when I clicked home icon.
Sir how to stop fragment recreation every time the tabs clicked? When one tab is clicked first time the fragment should be created but when the same tab is clicked second time I don't want to recreate the fragment so is there any way to achieve that?
Thx for the video. There is no tutorial like this if possible do that creating a list item with images from previous activity with eduit text and listview
val appBarConfiguration=AppBarconfiguration(setof(R.id.firstFragment,R.id.seconfFragement,R.id.thirdFragement)); setupActionBarWithNacController(navController,appBarConfiguration) im have trouble to fine the equivalent syntax in JAVA Can Any one help me out
Here it is: Set topLevelDestinations = new HashSet(); topLevelDestinations.add(R.id.firstFragment); topLevelDestinations.add(R.id.secondFragment); topLevelDestinations.add(R.id.thirdFragment); AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(topLevelDestinations).build(); NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
Does bottom nav view have any perofmance impact? i mean i have 4 views and i want the user to be able to switch between them. tab layout vs bottomnavview?
Can you make a tutorial about the basics and advance tricks with recyclerView? I already know the basics, I just dont know how to make each element become clickable and have separate pages for each element each time theyre clicked.
I have a question how do I stop the bottom navigation from recreating the view when its selected and I keep clicking on it like in your example if you keep clicking on any of the items it will keep recreating the corresponding fragment ?
@@StevdzaSan Thanks but I can't do that. It won't let me assign any animations unless I connect the fragments with arrows and even if I connect them and set the animations, they don't work when I run it.
@@StevdzaSan Thanks, man. You and your channel rock! It's comprehensible, great voice over, perfect presentation and you respond to comments. Others should follow your example.
Java code of 5:55
BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
NavController navController = Navigation.findNavController(this, R.id.fragment);
NavigationUI.setupWithNavController(bottomNavigationView, navController);
I can't click the other icons with this code.
Thanks man, you really helped me with my project
Thanxs
Thank you man.. Life saver
Thanks, bro
to anyone whose app crashes when you do this.
change the navhost package tag in activity_main.xml to just fragment or your app will crash. thank you so much to the poster of this video. you were very clear and easy to understand. it was just that little detail in the tag that was driving me crazy cuz my app kept crashing. lol. hope this helps someone!
for me it crashed because I used FragmentContainerView instead of fragment, I changed it to fragment and then it works fine
Thank you so much!
Thank you shinmasterx
@@skyfeelan bro could u just provide this line of code. i am facing the same issue too. can't resolve
@@sayanadhikari3220 sorry, but rn I'm on a deadline of something, 😭 and also I forgot the exact location of the project conatining the code pertaining that problem
Very professional . to the point , knows when to slow and when to speed . Followed the tutorial and was able to generate the needed UI . Thanks
I like this video, not because it's perfect or anything, but it shows someone using android studio and not just writing xml like everyone and their mothers.
Holy shit, your content is Gold! I thought I was becoming stupid due to listening to those unclear tutorials, but yours was clear and spot on. Thanks man!
Also the java code for the AppBarConfiguartion is;
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.firstFragment, R.id.secondFragment, R.id.thirdFragment).build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
Such an amazing, concise and straight up tutorial! You're a genius, thank you!
BEST TUTORIAL EVER! THANK YOU SO MUCH YOU'RE A LIFESAVER
Хорошо что есть переводчик RUclips 😄.
Огромное вам спасибо за видео
It doesn't work for me!!!... The navigation between fragments doesn't work!.
It's not navigating fragments for me either :(
make sure you have the id of each fragment in each menu item: 4:30
4:21
I liked how he selected all (Ctrl + A) then pressed the magic key, then all took his place like a good solders :)
I've tried some keys and almost nuke my entire project, then I became like a good solder who must do boring stuff to my project :\
Ctrl + Alt + L
Thanks for making this comment since he replied.
i thought i was watching a speedrunner in mario maker but good vid tyvm!
short, precise and perfect explanation
Thank you 🙏💜
You're a life-saver. Cheers
This helped resolve 90% of my problems
Thank you so much my teacher didnt mention the fact that the icon item Id has to match fragment id found in bot nav menu
question :-
if I go from second fragment to third fragment then press back its back to Fragment One(home start destination ) but must be back to second Fragment .why?
Thanks for the video, exactly what I was looking for!
great videos !!,
Please make video about handling the backstack, its so difficult for me..,
this is my cases, here the flow of navigation graph :
1. A-B-C
2. D-B-F
The question is, how the B fragment knows, which fragment that called them, from A or D, i mean how to handle onBackpress,
im glad if u have the solution, thanks dude!
Thanks so much sir, it's working perfeclty. The only problem that i had was:
Kotlin recreted a "Fragment" intead "fragment", and you didnt show us that we needed to create an id on fragment, in the line: 25 of "activity_main". apartfrom that, everything is working. Thanks
Keep up the great work, Legend 🙌
What's the reason is used instead of FragmentContainerView??
There is confirmed bug (I don't remember what was that) in FragmentContainerView. For now Google suggests use fragment tag if we get bug until fix.
@@imc0der Thats true
Could you please share the source code of the following. I am having trouble importing correct libraries.
What about `FragmentContainerView`? Should we use that instead from now on?
The fragment is always re created every time you tap new tab, how to solved that?
@@nevermore5173 how pls help i noticed it and i need help
@@theworldminusraphtheninjat4378 This is a fairy simple project I discontinued. I used that technique in this app. Take a look:
github.com/Re1r0/StudyAssistant
Edit: I used a custom library because it looks good. But the same can be achieved using Google's de facto bottom navigation view.
oh Thanks!
sorry man, but if i want to combinate drawer navigation and bottom navigation with fragments. how would do it?
Hey you! You're very skilled with these design things! Thank you very much. Such an good explanation also
To the point. Amazing work, thank you for sharing!
You're welcome 😊
Thanks for the great tutorial, I've got it implementet and it works!!!
Keep up the good work!
Short and useful tutorial thanks a lot!
I was stuck with the problem of switching the fragments when pressing the bottom navbar items but when i set the same id of fragments in my_nav and items in bottom_nav (menu) it runs succesfully.
If this code don't work. Perhaps this will help you:
val navHostFragment =
supportFragmentManager.findFragmentById(R.id.fragment) as NavHostFragment
val navController = navHostFragment.navController
findViewById(R.id.bottomNavigationView)
.setupWithNavController(navController)
Thank you, this fixed my issue
I have a problem with this:
I have created the fragments, but i have a google maps activity, that i want to add in the navbar.
I put it in my:nav.xml and detects that is an activity.
When i run my app i can navigate normaly, but when i press in Maps button it crashes.
Any solution to implements a normal activity?
Thank you so much for this!
Your videos are very helpful. Thank you very much.
You're welcome 👍
It is good tutorial. I did all but when I click the icons, the app goes wrong and disappear from the emulator. And when I remove the fragments, I can see the icons but they don't listen at all. And the other thing is, I couldn't get the titles with the icons. Why? Android Studio couldn't detect me where I missed it. Please help me.
Thank you! Helped me a lot!
Amazing work, clear explanation! Thank you.
Thanks! for sharing this tutorial, very helpful
Thank you so much for this excellent tutorial
Anytime!
Thank you worked 100% much appreciated !
Glad you like it buddy!
@@StevdzaSan Hi I just want to ask you if you please this question: I created a button in the home fragment that takes me to a fourth fragment (not included in the navigation bar), and when navigating to another fragment from the bar, and then clicking the home button from the navigation bar, that 4th fragment is still, I want to return to the home.If u can suggest a way.Thanks!
how to make all the text on the button visible, the text on the button should be visible even if you do not press the button.
please help me
Stevdza-San
I like your way of explanation
Thumbs up for you my friend. Thank you!
Great video, helped me a lot.
Thanks 🙌
very clear and helpful!
Hello, I have a question, how can I update a values other fragments, for example i have an app that can save some tasks, so i have one fragment to show tasks and another one to set and save tasks, but fragment pages do not refreshed or reload so it problematic to me, to show the added or updated data instead of just switching fragment I am turning off the app and turn un, so how can I solve it?
This is awesome.
How about to swipe left and right those 3 fragments? I have no clue
If you add setOnItemSelectedListener for the menu, do you need then to manually add the transition to the fragments?
another applauder!!! thank you
It was a nice video but one thing I'd like to bring to your notice is that I didn't get to use app bar configuration object. Action bar's title was changing with just a method which is set up action bar with nav controller and with just one parameter navController. So why did you make that extra instance of app bar configuration?
Nice work, very helpful video
Thanks for help, you are my hero
How can we do this inside a fragment and in Java? I tried my best but it won't work
why my fragment didnt become class, even though they are class. i already follow all instruction rewacth video 3x. pretty sure im have same code with u. but the app crashed...
Very nice, thanks so much
We have 3 top-level destinations (first fragment, second ... and third), when I click BottomNavigationView to navigete to second or third fragment, then press the back button, it will always come back to first fragment. Only when I'm in first fragment, press the back button can exit the activity. How to make exit activity when I cpress back button no matter what fragment I'm in?
Did you ever find a solution to this?
You are the best!
Thanks for information 👍
Hi there i used your tutorial and it works perfectly but im facing the issue that it seems to override my start activity which is my login activity and launches this bottom navigation activity first each time. Is there any fix to this?
NICE TUTORIAL! But every time I click the menu item, the fragment will be refreshed, causing crash. How am I supposed to deal with it?
Is this a Java tutorial or Kotlin? and plz let us know ahead of time if you will be working with Kotlin or Java i like to stay consistent...Anyways great job sir thanks
Hello sir what is the your Button navigation dependency?
Java Code of 7:00
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
R.id.firstFragment, R.id.secondFragment, R.id.thirdFragment)
.build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
In Java i tried using AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(R.id.firstFragment, R.id.secondFragment, R.id.thirdFragment).build();
and
NavigationUI.setupWithNavController(appBarConfiguration);
to update the top app bar. However, android is telling me "Cannot resolve method setUpWithNavController(appBarConfiguration)"
does anyone know how to resolve this?
Refer to the comment with highest number of likes
@@StevdzaSan It doesnt change the title when the app navigates to a new fragment. Please look into it. even your code that you ask to refer to doesn't change it
@@mrowox In your nav graph, just change label attribute.
@@StevdzaSan it still shows the same thing. I really can't figure out what is wrong because I am new to this
Here it is:
Set topLevelDestinations = new HashSet();
topLevelDestinations.add(R.id.firstFragment);
topLevelDestinations.add(R.id.secondFragment);
topLevelDestinations.add(R.id.thirdFragment);
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(topLevelDestinations).build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
The fragments get destroyed when user moves to another fragment... is there a way to save the fragment state with this?
Same issue for me....
@@sambhusbabu So what I did was not use this navigation component library, I chose to add fragments and hide/show the other fragment based on user interaction, thus saving the states
My BottomNavigationView is not showing up at the bottom, any suggestions?
Can I adjust the size and spacing of the navigation icon? Can I put in Chrome Icon and make the start menu and program list appear like Windows?
Can someone help me? I have the exact same code as the video with, the only difference is that a fragment from a nav_graph to an another activity (HomeActivity) with another (surely in the future) nav_graph navigation. The problem is that all navigation function well but the AppBar and the BottomNavigationView doesn't display at the activity and seems like it only renders the pure fragment with the text. can someone help me?
Awesome like usual, but I prefer Java instead of kotlin. One like.
You can use both of them in one project. Copy Kotlin code and paste it in java class, android studio will automatically convert it to java for you.
Hi nice tutorial. How can I add gridView in Home Fragment ? I can create gridView other app in mainActivity bu I can't open gridView when I clicked home icon.
great tutorial
How to not display the text in the menu title? i want to just show the menu icon and not the title text with it take the space
Get rid of the Title attribute
how can we handle multiple navigation graph for managing multiple backstacks
Sir how to stop fragment recreation every time the tabs clicked?
When one tab is clicked first time the fragment should be created but when the same tab is clicked second time I don't want to recreate the fragment so is there any way to achieve that?
Thanks bro
Thank you!!!
thank you
4:22 to 4:23
What did input on keyboard to change coding style?
Right now im having problems because the activity_main_fragment.xml is supposed to have instead of , do you know how to handle this?
excelent thanks
thanks😍
Thx for the video. There is no tutorial like this if possible do that creating a list item with images from previous activity with eduit text and listview
val appBarConfiguration=AppBarconfiguration(setof(R.id.firstFragment,R.id.seconfFragement,R.id.thirdFragement));
setupActionBarWithNacController(navController,appBarConfiguration)
im have trouble to fine the equivalent syntax in JAVA
Can Any one help me out
Here it is:
Set topLevelDestinations = new HashSet();
topLevelDestinations.add(R.id.firstFragment);
topLevelDestinations.add(R.id.secondFragment);
topLevelDestinations.add(R.id.thirdFragment);
AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(topLevelDestinations).build();
NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
@@sinbobey39 very helpful for java code
Perfect
Does bottom nav view have any perofmance impact? i mean i have 4 views and i want the user to be able to switch between them.
tab layout vs bottomnavview?
Please translate this into java
val appBarConfigutation = AppBarConfiguration(setOf(R.id.firstfragment, R.id.firstfragment, R.id.firstfragment))
It's possible to save the state of the fragments between transition of fragments with this code?
I have one question . If I want to add two fragment in profile tab ... how to do that
how can I set a particular fragment as the starting fragment....which appears first on opening app
okay
Can you make a tutorial about the basics and advance tricks with recyclerView? I already know the basics, I just dont know how to make each element become clickable and have separate pages for each element each time theyre clicked.
Hello sir, did you found it? I can help with that if you want!
I have a question how do I stop the bottom navigation from recreating the view when its selected and I keep clicking on it
like in your example if you keep clicking on any of the items it will keep recreating the corresponding fragment ?
Same problem... Help me to fix this issue
Can you apply transition animations using this method?
Yes and it's easy. You just specify transition animation in Navigation graph.
@@StevdzaSan Thanks but I can't do that. It won't let me assign any animations unless I connect the fragments with arrows and even if I connect them and set the animations, they don't work when I run it.
@@TBrianOnline I'll make a video about transition animations using navigation component. Expect it soon.
@@StevdzaSan Thanks, man. You and your channel rock! It's comprehensible, great voice over, perfect presentation and you respond to comments. Others should follow your example.
awesome bro >
but how i can pass args from fragment to anther ??
Could you find your question's answer?
How can I add transition animations between those fragments?
Please if anyone can answer me. How to customize the toolbar according to the fragment I am in?
can you change the blue color of the selected item?
Please create the "Bottom Navigation View " for JAVA programming environment. I'm not using Kotlin.
Thank you very much.
I have the same problem..
If you are using Android Studio, it allows you to change individual files to Kotlin
Sorry I think there is a misunderstanding. I don't want in Kotlin. I want in Java. Don't like Kotlin.
Hii could you please tell about how to use searchbar in bottom navigation
why I cant run this project it keeps on crashing, I did it the way he did it I just follow these step by step
I have the same problem right now :'( did you find the solution?