tryad1tk

Friday, 19 February 2016

Navigation Drawer Activity with Fragments

Go to Android Studio,start new project and enter the desired name for your app.Then, in the next step Select the Navigation Drawer Activity and click Next.  As shown below



Click next and then press finish.
Now your app will be build, wait and then Continue Your project will look like this-



layout named as content_main.xml is the layout which will be shown first when you open your app

You can either edit this layout or create a new layout and call that layout using savedinstance ==null as the first layout.

Firstly edit your content_main.xml by removing tools:showIn="@layout/app_bar_main" this line and edit the app_bar_main.xml as follows-

we have added Framelayout So that each fragment would be replaced by other

Here what we want to do is open new fragment everytime the user selects an option from navigation drawer.

we have added Framelayout So that each fragment would be replaced by other

create a new layout named as lay1.xml as follows-


Now we will create a new class that will extend Frgaments and will use this new lay1.xml as its View

Create new class named as Frag1.Java-


Similarly create other layout like,lay1.xml and also create seperate Fragment Class like Frag1.Java

Now call this fragment using getSupportFragementManager() Method in MainActivity or any other desired place-



Check its .apk
get the whole project
here

Comment or send your feedback for more codes.

No comments:

Post a Comment