I need to access my header items from a Fragment but I can't find a way to do it. I've seen:
View headerLayout = navigationView.getHeaderView(0);
However, I am not working on the NavigationDrawerActivity itself. I have to access it inside a Fragment alone. Is there a way for me to achieve that?
It's easy! getHeaderView() can be called from an Activity. But, as you are in a Fragment, you just need to getActivity from the Fragment and then call getHeaderView()...
SOLUTION:
In your Fragment:
NavigationView navigationView = (NavigationView) getActivity().findViewById(R.id.nav_view);
View headerView = navigationView.getHeaderView(0);
I hope it helps! Let me know if it didn't work!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With