Various ways of creating android navigation drawer
Using a standard android navigation drawer has always been a challenging one, due to the various ways of creating them. Latest versions of android studio comes inbuilt with startup templates of the navigation drawer making it easy for developers to implement the navigation drawer without the headache of randomly selecting a perfect method. I have put forward the various different snippets relating to different ways by which the navigation drawer can be put in place. Below is further description of the various techniques of setting up the navigation drawer
1. Using fragments
Github link: https://github.com/devDeji/FragmentNavFiles
Activity_main.xml - This uses a combination of the toolbar and frame imbedded in a linearlayout alongside the fragment as illustrated below
<android.support.v4.widget.DrawerLayout <include android:id="@+id/toolbar"layout="@layout/toolbar" /> <FrameLayout> <fragment>
Toolbar.xml
<android.support.v7.widget.Toolbar/>
With the drawer inflated in the java file as illustrated below
MainActivity.java
mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer); drawerFragment.setUp(R.id.fragment_navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
The fragmentDrawer API provides a neat method setUp which is used to populate
the drawerFragment with the toolbar, in further post I will touch on the other methods
for creating a navigation drawer.
Comments
Post a Comment