‫Hello, my friends.
‫Now open main activity and start initializing the widgets and the navigation drawer.
‫And let's add the functionality for this nav drawer.
‫We will start by late initializer.
‫And var toggle.
‫I will name it as toggle its type as an action bar drawer toggle.
‫This will be representing the three dashes that allows the user to click on them to display the navigation
‫drawer.
‫Okay now.
‫The toggle equal to action bar drawer toggle.
‫And here I need to pass these parameters.
‫So if we look closer here, we need to pass the four parameters.
‫If I hover.
‫There are.
‫These are the constructors activity draw, end and end.
‫So I will use this constructor.
‫I will start with this at main activity.
‫This is the main activity I need to to add the draw.
‫Lay out here.
‫Draw.
‫Lay out.
‫So.
‫So I need to create a variable here.
‫An instance from the draw layout so far draw.
‫Layout its type.
‫Is a drawer layout equal find view by ID or that id dot the navigation drawer.
‫The nav view.
‫This is the drawer layout.
‫If we go click alt or control and the left mouse, we can see that it is a navigation view here.
‫And this is what we've created before.
‫Now, let's continue with this.
‫Parameters.
‫R dot string or open.
‫I can specify.
‫Here.
‫Open and here.
‫Close.
‫Okay.
‫Here I need to specify the draw content description resources.
‫So I will remove the open and I will replace it with string dot open.
‫And here the same thing.
‫R dot string dot close.
‫Why I am doing this because it represents from me and request from me to create these two strings for
‫opening and closing.
‫These are for the titles.
‫Okay.
‫So I need to extract these resources inside the the resources folder and here I will type open as a
‫value.
‫And for this alt+ enter.
‫Or I can specify like this.
‫Values strings.
‫You can see that Android studio created this for me and I will change close to close.
‫Okay.
‫These are the open and close.
‫Strings.
‫Now to combine the toggle, this toggle that we've created with the draw that we've created, we need
‫to add a draw layout.
‫Add, draw listener and we pass the toggle that we have created toggle dot sync State.
‫So it's opened if the user clicks back.
‫So it will close.
‫If it is closed, if the user clicks on the toggle, it will open the nav drawer.
‫Okay.
‫This is very important point.
‫Now I will use support action bar dot set display home as enabled to true.
‫We specify.
‫Death in the home is enabled, the home fragment will be enabled and displayed first.
‫Now let's add the functionality for functionalities for the nav drawer items.
‫We will start with nav view, which is the drawer layout.
‫Dot set navigation.
‫I will change it to nav view.
‫So i will create val nav.
‫View.
‫Dot
‫nav view.
‫Equal find view by ID or.id, dot nav view.
‫And now I will set the nav view dot set navigation item selected listener and here I will pass.
‫It is clicked.
‫I will check it.
‫That is checked set navigation item selected the listener is it checked equal to true?
‫So I'm starting with the clicked interface.
‫Now I will start with when?
‫When it's the case for in Kotlin.
‫So I'm studying the cases in Kotlin.
‫If it is selecting the home message settings or login.
‫Start by it.
‫Dot item ID.
‫This is a switch.
‫Think about it as a switch.
‫We start by studying if it is.
‫The case of home.
‫What we will do.
‫We are going to replace the fragment.
‫I will call this method and I will set the home fragment.
‫With it.
‫Dot title dot to string.
‫Okay, I will create this.
‫This method replace fragment here.
‫If I go up?
‫This is for the Oncreate so I will create a private function replace fragment.
‫It took into the parameter if fragment and the title which is of type string.
‫Okay.
‫Alt+ enter to import the fragments class and here we will start replacing here the transaction of the
‫fragments will took place.
‫So please guys concentrate with me.
‫Fragment Manager equal to support action or support.
‫Fragment Manager.
‫Val Fragment Transaction
‫Equal Fragment Manager.
‫Dot begin Transaction.
‫Fragment.
‫Transaction.
‫Dot replace I'm replacing here.
‫I'm calling the method replace r.id dot frame layout one with a fragment that I have passed to as a
‫parameter.
‫Okay.
‫So I'm replacing the frame layout with the passed fragment.
‫Now I will comment.
‫Comment this transaction.
‫So fragment transaction dot comment and we will set the title to title.
‫So set title to title the passed parameter here and I need to close the draw.
‫Draw.
‫Layout.
‫NAV layout what it's named.
‫It's.
‫For.
‫Draw layout will change it to draw layout.
‫NAV draw.
‫The layout is draw layout.
‫Sorry.
‫So draw layout equal to or that close draws.
‫Okay.