BottomNavigationView with Navigation Component - Android Studio Tutorial

Поделиться
HTML-код
  • Опубликовано: 26 ноя 2024

Комментарии • 329

  • @bryanmoreno626
    @bryanmoreno626 4 года назад +496

    Java code of 5:55
    BottomNavigationView bottomNavigationView = findViewById(R.id.bottomNavigationView);
    NavController navController = Navigation.findNavController(this, R.id.fragment);
    NavigationUI.setupWithNavController(bottomNavigationView, navController);

  • @shinmasterx
    @shinmasterx 2 года назад +3

    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!

    • @skyfeelan
      @skyfeelan 2 года назад +2

      for me it crashed because I used FragmentContainerView instead of fragment, I changed it to fragment and then it works fine

    • @Laughing-Pixels
      @Laughing-Pixels Год назад +1

      Thank you so much!

    • @zolo375
      @zolo375 9 месяцев назад

      Thank you shinmasterx

    • @sayanadhikari3220
      @sayanadhikari3220 4 месяца назад

      @@skyfeelan bro could u just provide this line of code. i am facing the same issue too. can't resolve

    • @skyfeelan
      @skyfeelan 4 месяца назад +1

      @@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

  • @justaaq
    @justaaq 4 года назад +30

    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

  • @blueicer101
    @blueicer101 2 года назад

    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.

  • @BrandCatalogs
    @BrandCatalogs 4 года назад

    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!

  • @jamieholmes6379
    @jamieholmes6379 3 года назад +5

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

  • @evelynediazaraque6095
    @evelynediazaraque6095 4 года назад +2

    Such an amazing, concise and straight up tutorial! You're a genius, thank you!

  • @queenvillarin4496
    @queenvillarin4496 3 года назад +1

    BEST TUTORIAL EVER! THANK YOU SO MUCH YOU'RE A LIFESAVER

  • @Arman_127
    @Arman_127 2 года назад

    Хорошо что есть переводчик RUclips 😄.
    Огромное вам спасибо за видео

  • @edycarreyes99
    @edycarreyes99 4 года назад +17

    It doesn't work for me!!!... The navigation between fragments doesn't work!.

    • @crooks5001
      @crooks5001 3 года назад

      It's not navigating fragments for me either :(

    • @andres1f1guti1s
      @andres1f1guti1s 3 года назад

      make sure you have the id of each fragment in each menu item: 4:30

  • @Techavior
    @Techavior 4 года назад +10

    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 :\

  • @jacoblee89
    @jacoblee89 4 года назад +2

    i thought i was watching a speedrunner in mario maker but good vid tyvm!

  • @mkc0321
    @mkc0321 3 года назад +1

    short, precise and perfect explanation

  • @muminoloruntola2146
    @muminoloruntola2146 4 года назад

    You're a life-saver. Cheers
    This helped resolve 90% of my problems

  • @NiteSeek
    @NiteSeek 3 года назад +1

    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

  • @mohammedabusnaimeh8076
    @mohammedabusnaimeh8076 2 года назад +2

    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?

  • @johnshepard1267
    @johnshepard1267 4 года назад +5

    Thanks for the video, exactly what I was looking for!

  • @telloborneo3635
    @telloborneo3635 4 года назад +2

    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!

  • @maviniii
    @maviniii 2 года назад +1

    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

  • @h.r.60
    @h.r.60 4 года назад +2

    Keep up the great work, Legend 🙌

  • @ApratimArora
    @ApratimArora 2 года назад +1

    What's the reason is used instead of FragmentContainerView??

    • @imc0der
      @imc0der Год назад +1

      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.

    • @name1566
      @name1566 Год назад

      ​@@imc0der Thats true

  • @nitin88mehta
    @nitin88mehta 4 года назад +5

    Could you please share the source code of the following. I am having trouble importing correct libraries.

  • @computinghub9550
    @computinghub9550 Год назад +1

    What about `FragmentContainerView`? Should we use that instead from now on?

  • @pauljohn.ytchannel
    @pauljohn.ytchannel 4 года назад +6

    The fragment is always re created every time you tap new tab, how to solved that?

    • @theworldminusraphtheninjat4378
      @theworldminusraphtheninjat4378 4 года назад

      @@nevermore5173 how pls help i noticed it and i need help

    • @nevermore5173
      @nevermore5173 4 года назад

      @@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.

  • @D3r_3k_
    @D3r_3k_ 4 года назад +2

    oh Thanks!
    sorry man, but if i want to combinate drawer navigation and bottom navigation with fragments. how would do it?

  • @fausto7394
    @fausto7394 3 года назад

    Hey you! You're very skilled with these design things! Thank you very much. Such an good explanation also

  • @maleehamuzafar
    @maleehamuzafar 3 года назад +1

    To the point. Amazing work, thank you for sharing!

  • @theisikkala7918
    @theisikkala7918 4 года назад

    Thanks for the great tutorial, I've got it implementet and it works!!!
    Keep up the good work!

  • @alonsoescamillarc948
    @alonsoescamillarc948 4 года назад

    Short and useful tutorial thanks a lot!

  • @usamazafar337
    @usamazafar337 3 года назад +1

    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.

  • @pauilegorov
    @pauilegorov 2 года назад +2

    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)

    • @ryderr4453
      @ryderr4453 2 года назад +2

      Thank you, this fixed my issue

  • @albertperellacanelles1314
    @albertperellacanelles1314 3 года назад +1

    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?

  • @saravananmanoharan4114
    @saravananmanoharan4114 3 года назад +1

    Thank you so much for this!

  • @prasannadeshpande4435
    @prasannadeshpande4435 3 года назад

    Your videos are very helpful. Thank you very much.

  • @ethiomusic3158
    @ethiomusic3158 3 года назад

    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.

  • @Feciboy
    @Feciboy 3 года назад

    Thank you! Helped me a lot!

  • @seyhmusalatas1740
    @seyhmusalatas1740 Год назад

    Amazing work, clear explanation! Thank you.

  • @hisanahsalsabila8248
    @hisanahsalsabila8248 4 года назад

    Thanks! for sharing this tutorial, very helpful

  • @ryderr4453
    @ryderr4453 2 года назад

    Thank you so much for this excellent tutorial

  • @mohammadalameh9434
    @mohammadalameh9434 2 года назад

    Thank you worked 100% much appreciated !

    • @StevdzaSan
      @StevdzaSan  2 года назад

      Glad you like it buddy!

    • @mohammadalameh9434
      @mohammadalameh9434 2 года назад

      @@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!

  • @Normatov
    @Normatov 4 года назад +1

    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.

    • @Normatov
      @Normatov 4 года назад

      please help me

    • @Normatov
      @Normatov 4 года назад

      Stevdza-San

  • @allandrifqyputra4422
    @allandrifqyputra4422 2 года назад

    I like your way of explanation

  • @timverlinde8954
    @timverlinde8954 3 года назад

    Thumbs up for you my friend. Thank you!

  • @GamesLooping
    @GamesLooping 2 года назад

    Great video, helped me a lot.

  • @cindyliang9367
    @cindyliang9367 3 года назад

    very clear and helpful!

  • @10wyk-f2y
    @10wyk-f2y Год назад

    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?

  • @ericsatriawan674
    @ericsatriawan674 2 года назад

    This is awesome.
    How about to swipe left and right those 3 fragments? I have no clue

  • @dirtypaws17
    @dirtypaws17 Год назад

    If you add setOnItemSelectedListener for the menu, do you need then to manually add the transition to the fragments?

  • @aelafdev
    @aelafdev 4 года назад

    another applauder!!! thank you

  • @Ari-118
    @Ari-118 3 года назад

    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?

  • @ioannismitropoulos6754
    @ioannismitropoulos6754 2 года назад +1

    Nice work, very helpful video

  • @leonardocorreiadecastro5701
    @leonardocorreiadecastro5701 3 года назад

    Thanks for help, you are my hero

  • @nevermore5173
    @nevermore5173 4 года назад +1

    How can we do this inside a fragment and in Java? I tried my best but it won't work

  • @lighttangoredox1573
    @lighttangoredox1573 4 года назад +1

    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...

  • @abdremo
    @abdremo 4 года назад

    Very nice, thanks so much

  • @binqiangliang4745
    @binqiangliang4745 2 года назад

    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?

    • @ishchuk_
      @ishchuk_ Год назад

      Did you ever find a solution to this?

  • @DavisTibbz
    @DavisTibbz 4 года назад

    You are the best!

  • @sjjayaswal7621
    @sjjayaswal7621 2 года назад

    Thanks for information 👍

  • @lukefernandez949
    @lukefernandez949 Год назад

    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?

  • @toBeABetterTranslator
    @toBeABetterTranslator 3 года назад

    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?

  • @footballfreak3987
    @footballfreak3987 4 года назад +1

    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

  • @rockymalobago4075
    @rockymalobago4075 3 года назад

    Hello sir what is the your Button navigation dependency?

  • @A_S996
    @A_S996 2 года назад

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

  • @spartan10234
    @spartan10234 4 года назад +2

    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
      @StevdzaSan  4 года назад

      Refer to the comment with highest number of likes

    • @mrowox
      @mrowox 4 года назад

      @@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

    • @StevdzaSan
      @StevdzaSan  4 года назад

      @@mrowox In your nav graph, just change label attribute.

    • @mrowox
      @mrowox 4 года назад

      @@StevdzaSan it still shows the same thing. I really can't figure out what is wrong because I am new to this

    • @sinbobey39
      @sinbobey39 4 года назад +1

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

  • @anudeepananth
    @anudeepananth 4 года назад +2

    The fragments get destroyed when user moves to another fragment... is there a way to save the fragment state with this?

    • @sambhusbabu
      @sambhusbabu 4 года назад

      Same issue for me....

    • @anudeepananth
      @anudeepananth 4 года назад +1

      @@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

  • @Rafael-hk9pg
    @Rafael-hk9pg 4 года назад +1

    My BottomNavigationView is not showing up at the bottom, any suggestions?

  • @uio86a
    @uio86a 2 года назад

    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?

  • @chil1t0
    @chil1t0 Год назад

    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?

  • @jjb5142
    @jjb5142 4 года назад +4

    Awesome like usual, but I prefer Java instead of kotlin. One like.

    • @StevdzaSan
      @StevdzaSan  4 года назад +1

      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.

  • @aozgunn
    @aozgunn 4 года назад

    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.

  • @quynhnguyen1018
    @quynhnguyen1018 3 года назад

    great tutorial

  • @ShivamMalik95
    @ShivamMalik95 3 года назад +2

    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

  • @harshpatel-bt5wr
    @harshpatel-bt5wr 3 года назад

    how can we handle multiple navigation graph for managing multiple backstacks

  • @ahmedbasalib7598
    @ahmedbasalib7598 3 года назад

    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?

  • @alexandryuschenko3334
    @alexandryuschenko3334 3 года назад

    Thanks bro

  • @israelmityabeshet5970
    @israelmityabeshet5970 3 года назад

    Thank you!!!

  • @musasoydas3122
    @musasoydas3122 Год назад

    thank you

  • @mohamadmf4105
    @mohamadmf4105 3 года назад

    4:22 to 4:23
    What did input on keyboard to change coding style?

  • @ferranescolano6491
    @ferranescolano6491 4 года назад

    Right now im having problems because the activity_main_fragment.xml is supposed to have instead of , do you know how to handle this?

  • @juliocamacho6298
    @juliocamacho6298 3 года назад

    excelent thanks

  • @mohammadaliltf4067
    @mohammadaliltf4067 2 года назад

    thanks😍

  • @pandakaradi4959
    @pandakaradi4959 4 года назад

    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

  • @reinhardkenson
    @reinhardkenson 4 года назад +1

    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

    • @sinbobey39
      @sinbobey39 4 года назад +6

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

    • @mamaminiepozwoliaukrzyska6774
      @mamaminiepozwoliaukrzyska6774 3 года назад

      @@sinbobey39 very helpful for java code

  • @muh442
    @muh442 3 года назад

    Perfect

  • @hatty101
    @hatty101 4 года назад

    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?

  • @fineline392
    @fineline392 4 года назад +1

    Please translate this into java
    val appBarConfigutation = AppBarConfiguration(setOf(R.id.firstfragment, R.id.firstfragment, R.id.firstfragment))

  • @AlanBlay
    @AlanBlay 3 года назад

    It's possible to save the state of the fragments between transition of fragments with this code?

  • @ManishKumar-lr9ig
    @ManishKumar-lr9ig 2 года назад

    I have one question . If I want to add two fragment in profile tab ... how to do that

  • @utksingh7
    @utksingh7 4 года назад

    how can I set a particular fragment as the starting fragment....which appears first on opening app

  • @_tema
    @_tema Год назад +1

    okay

  • @BrandCatalogs
    @BrandCatalogs 4 года назад

    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.

    • @fausto7394
      @fausto7394 3 года назад

      Hello sir, did you found it? I can help with that if you want!

  • @theworldminusraphtheninjat4378
    @theworldminusraphtheninjat4378 4 года назад

    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 ?

    • @sambhusbabu
      @sambhusbabu 4 года назад

      Same problem... Help me to fix this issue

  • @TBrianOnline
    @TBrianOnline 4 года назад +1

    Can you apply transition animations using this method?

    • @StevdzaSan
      @StevdzaSan  4 года назад +1

      Yes and it's easy. You just specify transition animation in Navigation graph.

    • @TBrianOnline
      @TBrianOnline 4 года назад

      @@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
      @StevdzaSan  4 года назад +1

      @@TBrianOnline I'll make a video about transition animations using navigation component. Expect it soon.

    • @TBrianOnline
      @TBrianOnline 4 года назад

      @@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.

  • @abdnezar5872
    @abdnezar5872 4 года назад +1

    awesome bro >
    but how i can pass args from fragment to anther ??

  • @albertomagalhaes5118
    @albertomagalhaes5118 2 года назад

    How can I add transition animations between those fragments?

  • @brunooliveira3931
    @brunooliveira3931 10 месяцев назад

    Please if anyone can answer me. How to customize the toolbar according to the fragment I am in?

  • @pvelasquez
    @pvelasquez 3 года назад

    can you change the blue color of the selected item?

  • @crissb9357
    @crissb9357 3 года назад +1

    Please create the "Bottom Navigation View " for JAVA programming environment. I'm not using Kotlin.
    Thank you very much.

    • @lukehectors6240
      @lukehectors6240 3 года назад

      I have the same problem..

    • @josepharteaga8576
      @josepharteaga8576 3 года назад

      If you are using Android Studio, it allows you to change individual files to Kotlin

    • @crissb9357
      @crissb9357 3 года назад

      Sorry I think there is a misunderstanding. I don't want in Kotlin. I want in Java. Don't like Kotlin.

  • @himanshumudgal8553
    @himanshumudgal8553 4 года назад

    Hii could you please tell about how to use searchbar in bottom navigation

  • @neoviray7248
    @neoviray7248 3 года назад +1

    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

    • @jeanmichel4269
      @jeanmichel4269 3 года назад

      I have the same problem right now :'( did you find the solution?