Can fragments itself host bottom navigation? I got...
# android
u
Can fragments itself host bottom navigation? I got it to work on activity class but I can't seem to implement it inside the fragments. The reason for wanting to add the bottom navigation to the fragment is because I want to build a single activity application. I actually created a stackoverflow question, and the post has more information about the code https://stackoverflow.com/questions/57514369/how-to-add-bottom-navigation-listeners-to-fragments. Any input suggestion is welcome 😊 thx.
a
off course you can, but I prefer to have a look to Navigation Component library, its so easy to implement instead of the regular code that could be a bit complicated to use in a single page applications navigation comp. lib built for that, I recommend to take a look here https://developer.android.com/guide/navigation
✔️ 2
u
I found
onNaviationItemSelectedListener
but it seems like it can only be used inside an activity, not a fragment. So this brings me back to my original question. Is fragment suitable for hosting bottom navigation? Or does it need to be done inside an AppCompatAcivity?
m
or you can build custom viewpager instead? *tablayout, inside the fragment, using navigation component to navigate to other fragment without tabs (viewpager)
u
Thanks I will check that out as well!