https://kotlinlang.org logo
#android
Title
# android
u

리오

08/15/2019, 8:39 PM
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

am414

08/15/2019, 9:12 PM
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

리오

08/15/2019, 9:36 PM
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

miqbaldc

08/16/2019, 2:05 AM
or you can build custom viewpager instead? *tablayout, inside the fragment, using navigation component to navigate to other fragment without tabs (viewpager)
u

리오

08/16/2019, 4:58 AM
Thanks I will check that out as well!