Navigation Drawer with Fragments Part 2 – LAYOUT AND HAMBURGER ICON – Android Studio Tutorial
In part 2 of the navigation drawer tutorial, we create the navigation drawer layout including the header. For this we set a DrawerLayout as the root view and put our content, consisting of a LinearLayout with a Toolbar and a FrameLayout, as the the first child view, and a NavigationView below it. This NavigationView will then contain the drawer itself. We set it’s layout_gravity to “start” to get a left-opening drawer, add a headerLayout to it and set fitsSystemWindows to true for our DrawerLayout to make it slide under the status bar, which we will then make transparent.
In the MainActivity we set our Toolbar as the ActionBar with the setSupportActionbar method.
We will also add a hamburger icon as the home button, which will open our drawer when clicked and also have a rotating animation while the navigation drawer is sliding. For this we use the ActionBarDrawerToggle class with it’s syncState method and set it as a listener to the DrawerLayout with addDrawerListener.
Lastly we will override onBackPressed to close our drawer there if it is opened.
Watch the whole playlist:
Example code for this part:
https://gist.github.com/codinginflow/b4e38b0c43780b47e833d77db86e8355
____________________
💻 Find the BEST programming tutorials on TutHub:
https://tuthub.io
⭐ Get my MVVM Caching Course now:
https://codinginflow.com/caching
❗ Subscribe to the channel:
https://www.youtube.com/c/codinginflo…
📨 Subscribe to the Coding in Flow newsletter:
https://codinginflow.com/newsletter
❓ Join our free developer community:
https://discord.gg/TSnMvmc
📣 Follow Coding in Flow on other sites:
Facebook: https://www.facebook.com/codinginflow
Instagram: https://www.instagram.com/codinginflow
TikTok: https://www.tiktok.com/@codinginflow
Twitter: https://twitter.com/codinginflow
Github: https://github.com/codinginflow
💰 Business requests, sponsoring, etc.: info@codinginflow.com
Views :404077
android studio