This post will help you install my Material Navigation Drawer template on Android Studio. This will help you create applications using material design faster than any other template.
First download the latest version of the template on my github:
https://github.com/kanytu/Android-studio-material-template
Your directory should now look like this:
Change the name of your application. Click next and set your minimum SDK. This library will only work for API level greater or equal than 7.
On Navigation Style there are 3 different styles:
And finally on Drawer Style there are 2 types:
Once you click `Finish` Android Studio will start building the project. After all the tasks are finished you can run your project and see your new application.
You can start working from here. Here are some TODO guide lines to help you:
Change NavigationDrawerFragment.getMenu() method in order to add, remove or change the contents of the menu:
Change colors.xml to change your theme colors:
Change onNavigationDrawerItemSelected to change your menu behavior:
Add items to main.xml to create a custom menu:
Keep adapting the code to your needs and happy programming :)
Example program code can be found here: https://github.com/kanytu/template_example
Note: The template might change once in a while. Make sure to check my github to keep your template up-to-date.
Note 2: Android Studio will remove the template on each update. You need to install it after each update.
First download the latest version of the template on my github:
https://github.com/kanytu/Android-studio-material-template
- Next copy the folder that's inside the root of the zip file, named `MaterialNavigationDrawerActivity`, to the directory located in :
Your directory should now look like this:
- Now restart your Android Studio and click on
Change the name of your application. Click next and set your minimum SDK. This library will only work for API level greater or equal than 7.
- Select Material Drawer Activity
- Now change the parameters according to your needs.
On Navigation Style there are 3 different styles:
And finally on Drawer Style there are 2 types:
Once you click `Finish` Android Studio will start building the project. After all the tasks are finished you can run your project and see your new application.
You can start working from here. Here are some TODO guide lines to help you:
Change NavigationDrawerFragment.getMenu() method in order to add, remove or change the contents of the menu:
public List getMenu() {
List items = new ArrayList();
items.add(new NavigationItem(getString(R.string.search), getResources().getDrawable(R.drawable.ic_action_search)));
items.add(new NavigationItem(getString(R.string.stats), getResources().getDrawable(R.drawable.ic_action_trending_up)));
items.add(new NavigationItem(getString(R.string.myaccount), getResources().getDrawable(R.drawable.ic_action_account_box)));
items.add(new NavigationItem(getString(R.string.settings), getResources().getDrawable(R.drawable.ic_action_settings)));
return items;
}
Change colors.xml to change your theme colors:
<color name="myPrimaryColor">#00BCD4</color>
<color name="myPrimaryDarkColor">#0097A7</color>
<color name="myAccentColor">#CDDC39</color>
Change onNavigationDrawerItemSelected to change your menu behavior:
@Override
public void onNavigationDrawerItemSelected(int position) {
Fragment fragment;
switch (position) {
case 0: //search//todo
break;
case 1: //stats
fragment = getFragmentManager().findFragmentByTag(StatsFragment.TAG);
if (fragment == null) {
fragment = new StatsFragment();
}
getFragmentManager().beginTransaction().replace(R.id.container, fragment, StatsFragment.TAG).commit();
break;
case 2: //my account //todo
break;
case 3: //settings //todo
break;
}
}
Add items to main.xml to create a custom menu:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:title="@string/action_search"
app:showAsAction="always"
android:icon="@drawable/ic_action_search_white"/>
<item
android:id="@+id/action_filter"
android:title="@string/action_filter"
app:showAsAction="ifRoom"
android:icon="@drawable/ic_action_filter_white"/>
</menu>
Keep adapting the code to your needs and happy programming :)
Example program code can be found here: https://github.com/kanytu/template_example
Note: The template might change once in a while. Make sure to check my github to keep your template up-to-date.
Note 2: Android Studio will remove the template on each update. You need to install it after each update.