Android Library for a DrawerLayout similar to the one in Google Apps

Overview

GoogleNavigationDrawerMenu

This project aims to let you use a ListView menu similar to the one in the new Google Apps (Keep, Play Music...) without having to do any extra effort. Sorry for the long name, though.

Screenshot

Index

Features

With GoogleNavigationDrawerMenu you can:

  • Set a GoogleApp-styled DrawerLayout menu and only have to specify the main content for your app, you no longer have set the ListView and its styles. Everything is handled by the GoogleNavigationDrawer class.
  • Set main and secondary sections to the menu.
  • Set a list of icons for those sections (optional).
  • Both text and icons remain selected when you click on them.
  • Set an OnNavigationSectionSelected listener so you can handle section selection events.
  • Change the background of the list items.
  • Set a header and footer to the inner ListView.

How to use

1. Include the library:

Manually (Option A):

Download the source code and import GoogleNavigationDrawerMenuLibrary folder as a Library Module in Android Studio or as a Project in Eclipse (still not tested).

Manually (Option B):

  • Download the AAR.

  • Put it in the aars folder of your Android Studio project.

  • Add a File Dependency or add it to the build.gradle of your main Module, like this:

    repositories {
      mavenCentral()
      flatDir {
          dirs 'aars'
      }
    }
    

Notice the flatDir local maven repository created. Now you will have to add the aar file to the dependencies list, as if you were adding it from Maven Central Repository:

    compile 'com.arasthel:gnavdrawer-library:+'

Automatic (Gradle):

Add it to your Application Module's build.gradle:

Declare it into your build.gradle

dependencies{
    compile 'com.arasthel:gnavdrawer-library:+'
}

2. Use class in XML or code:

Example of how to use it on an XML code:

<org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:drawer="http://schemas.android.com/apk/res-auto"
android:id="@+id/navigation_drawer_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
drawer:list_paddingTop="?android:actionBarSize"
drawer:drawer_gravity="start"
drawer:list_mainSectionsEntries="@array/navigation_main_sections"
drawer:list_secondarySectionsEntries="@array/navigation_secondary_sections"
drawer:list_mainSectionsDrawables="@array/drawable_ids"
drawer:list_secondarySectionsDrawables="@array/drawable_ids">

  <FrameLayout
      android:id="@+id/content_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>

</org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer>

You may think 'Ok, so where's the menu?'. Well, the GoogleNavigationDrawer class itself contains it and handles it so you don't have to manually modify it. You can customize it, though, you can find that info in Customizing Section.

All the drawer:* attributes are optional, but if you don't provide any entries you will have to do it later in code with drawer.setListViewSections(...).

Using GoogleNavigationDrawer in Java Code:

ViewGroup container = (ViewGroup) findViewById(R.id.container);
GoogleNavigationDrawer drawer = new GoogleNavigationDrawer(context);
// Here we are providing data to the adapter of the ListView
drawer.setListViewSections(new String[]{"Section A", "Section B"}, // Main sections
        new String[]{"Settings"}, // Secondary sections
        new int[]{R.drawable.ic_launcher}, // Main sections icon ids
        null); // Secondary sections icon ids
// To work correctly, a DrawerLayout must be the only View in a ViewGroup
container.removeAllViews();
container.addView(drawer);
// Now we add the content to the drawer since the menu is already there.
// Also, DrawerLayout forces the contentView to be the first item. Otherwise, you can't click on the menu.
drawer.addView(contentView, 0);

GoogleNavigationDrawer extends DrawerLayout. This means you can use DrawerLayout methods and set a DrawerListener to it.

3. Handling selection, opening and closing of the menu:

As you cannot access the inner ListView to ensure encapsulation, additional methods have been provided so you can do it by code. This methods are:

public boolean isDrawerMenuOpen();

public void openDrawerMenu();

public void closeDrawerMenu();

Also, to handle section selections, a listener has been provided:

public void setOnNavigationSectionSelected(OnNavigationSectionSelected listener);

You can also easily tell the drawer to change your Activity title based on the selected section via this method:

public void setShouldChangeTitle(Activity activity, boolean shouldChangeTitle);

4. Customizing the inner ListView:

Finally, customization. The main XML attributes of the class are the following:

drawer:list_padding[Top, Bottom, Left, Right]="dimen"
drawer:drawer_gravity="start"
drawer:list_mainSectionsEntries="array"
drawer:list_secondarySectionsEntries="array"
drawer:list_mainSectionsDrawables="array"
drawer:list_secondarySectionsDrawables="array"
drawer:list_headerView="layout"
drawer:list_footerView="layout"
drawer:list_headerClickable="boolean" (default is true)
drawer:list_footerClickable="boolean" (default is true)
drawer:list_secondarySectionsCheckable="boolean" (default is true)
drawer:list_mainSectionsBackground="drawable"
drawer:list_secondarySectionsBackground="drawable"
drawer:list_width="dimension"
drawer:list_background="drawable|color"
drawer:list_[main|secondary]_divider="drawable|color"
drawer:list_[main|secondary]_divider_height="dimension"

Example of arrays in arrays.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string-array name="navigation_main_sections">
        <item>Home</item>
        <item>Some Other</item>
    </string-array>

    <string-array name="navigation_secondary_sections">
        <item>Settings</item>
        <item>Info</item>
    </string-array>

    <array name="drawable_ids">
        <item>@drawable/ic_home</item>
        <item>@drawable/ic_other</item>
    </array>

</resources>

Also, both icon drawables and backgrounds should have checked states to keep them consistent with the rest of the library:

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/ic_on"></item>
    <item android:drawable="@drawable/ic_off"></item>
</selector>

All these attributes can also be set by code.

License:

This library is licensed under Apachev2:

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This means you can use the library in whatever way you want and also I take no responsibility of what it could do (thermo-nuclear explosions and such).

Anyway, it would be really nice of you if you could give this library a line in some "About" section in your app.

Comments
  • Add action bar title changing feature

    Add action bar title changing feature

    Hi,

    @Arasthel Thanks for this excellent library.

    Normal Navigation drawer has this feature but this doesn't I noticed that the action bar title doesn't change when navigation drawer is opened & revert back to old when navigation drawer is closed.

    opened by AkshayChordiya 12
  • Layout designer error

    Layout designer error

    The following classes could not be instantiated: - org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer (Open Class, Show Exception) Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details java.lang.UnsupportedOperationException   at android.content.res.BridgeResources.obtainTypedArray(BridgeResources.java:318)   at org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer.configureWithTypedArray(GoogleNavigationDrawer.java:231)   at org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer.(GoogleNavigationDrawer.java:89)   at java.lang.reflect.Constructor.newInstance(Constructor.java:526)   at android.view.LayoutInflater.inflate(LayoutInflater.java:469)   at android.view.LayoutInflater.inflate(LayoutInflater.java:373)"

    I think you should do nothing if it is View.isInEditMode()

    opened by yoavst 11
  • ArrayOutOfBoundsException when adding items

    ArrayOutOfBoundsException when adding items

    Hi! I've copied the exact same example from README.md and everything works with it. But when I add items in arrays.xml the app crashes with ArrayOutOfBoundsException. Here's the logcat:

    Caused by: java.lang.ArrayIndexOutOfBoundsException: length=12; index=12 at android.content.res.TypedArray.getResourceId(TypedArray.java:571) at org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer.configureWithTypedArray(GoogleNavigationDrawer.java:235) at org.arasthel.googlenavdrawermenu.views.GoogleNavigationDrawer.(GoogleNavigationDrawer.java:89)

    opened by ghost 5
  • Errors after adding library to project

    Errors after adding library to project

    So I've added the library to my project using Android Studio and I'm getting the following errors during gradle file synchronization:

    C:\Users\Andrew Quebe\Documents\Android Development\Projects\Planets-Gradle\libraries\Navigation-Drawer-Sample\src\main\java\org\arasthel\googlenavdrawermenu\views\GoogleNavigationDrawer.java
    Error:(194, 13) error: cannot find symbol variable isSecondarySectionsClickable
    Error:(194, 45) error: cannot find symbol variable IsSecondarySectionsClickable
    Error:(323, 126) error: TYPE_MAIN has private access in GoogleNavigationDrawerAdapter
    
    opened by ghost 5
  • Drawer won't fit the system window

    Drawer won't fit the system window

    When using actionBar overlay mode, it is not possible to have the drawer to fit the system window. It appears behind the actionBar. It can have the requested behavior with the DrawerLayout fron the support librarie.

    opened by StephaneBg 4
  • Fix for Layout Designer

    Fix for Layout Designer

    Should fix problem #14. Didn't tested it yet, but it should work, since the problem is in the adapter and this prevent the adapter from being called in edit mode.

    opened by yoavst 1
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 0
  • Add clickability for the header and footer

    Add clickability for the header and footer

    2 attrs: list_headerClickable, list_footerClickable. 2 methods:

    • public void setMenuHeader(View v, boolean b) -> b is the clickability of the header
    • public void setMenuFooter(View v, boolean b) -> b is the clickability of the footer
    opened by yoavst 0
  • Set height for header view

    Set height for header view

    Hi, I'm not enabled to set the height params for header view in my project... Pratically, I built an header layout but the layout_height doesn't seem to be read and when I execute the code, this height params was reset and I don't know why!

    This is my header view:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="@color/dark_gray">
    
        //...other widgets
    
    </RelativeLayout>
    

    When I try to change the layout_height (100dp in my snippet code), doesn't change the height when I execute the code...

    How can I solve?

    Thanks!!

    opened by robertotucci 0
  • Disable/enable only one item

    Disable/enable only one item

    Hi, I'd like a feature to enable or disable only one item in the main list. For example, the item disabled could have a grey background and it can't be checked. Is this possible? :)

    Thanks!

    opened by robertotucci 2
Owner
Jorge Martin Espinosa
Jorge Martin Espinosa
Bottom Navigation widget component inspired by the Google Material Design Guidelines at https://www.google.com/design/spec/components/bottom-navigation.html

Material Bottom Navigation Library Lightweight Bottom Navigation library component inspired by the Google Material Design Guidelines at https://www.go

Alessandro Crugnola 1.4k Dec 18, 2022
An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!

SlidingMenu (Play Store Demo) SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus li

Jeremy Feinstein 11.1k Dec 21, 2022
Kai Liao 2.2k Jan 3, 2023
Android library that provides the floating action button to sheet transition from Google's Material Design.

MaterialSheetFab Library that implements the floating action button to sheet transition from Google's Material Design documentation. It can be used wi

Gordon Wong 1.6k Dec 13, 2022
Space Navigation is a library allowing easily integrate fully customizable Google Spaces like navigation to your app.

Space-Navigation-View Introduction Space Navigation is a library allowing easily integrate fully customizable Google [Spaces][1] like navigation to yo

Arman 2k Dec 23, 2022
Navigation menu for Android (based off Google+ app)

RibbonMenu Navigation menu for Android (based on Google+ app). Usage Menus are created in xml as normal, adding text and an icon. In the layout you wa

David Scott 487 Nov 24, 2022
Implementation of "Side Navigation" or "Fly-in app menu" pattern for Android (based on Google+ app)

Android SideNavigation Library Implementation of "Side Navigation" or "Fly-in app menu" pattern for Android (based on Google+ app). Description The Go

Evgeny Shishkin 319 Nov 25, 2022
Floating Action Menu for Android. Inspired by the Google Plus floating menu

android-floating-action-menu Floating Action Menu for Android. Inspired by the Google Plus floating menu. Demo Setup The simplest way to use this libr

Alessandro Crugnola 242 Nov 10, 2022
BottomNavigationView Designed according Google guideLine

Material Bottom Navigation DEPRECATED Use offical Bottom Navigation BottomNavigationView Designed according Google [guideLine][1] [1]: https://www.goo

Arman 1k Oct 18, 2022
Android-NewPopupMenu 3.9 0.0 Java is an android library to create popup menu with GoogleMusic app-like style.

Android-NewPopupMenu Android-NewPopupMenu is an android library to create popup menu with GoogleMusic app-like style. Requirements Tested with APIv4 H

u1aryz 159 Nov 21, 2022
BottomSheet-Android - A simple customizable BottomSheet Library for Android Kotlin

BottomSheet-Android A simple customizable BottomSheet Library for Android Kotlin

Munachimso Ugorji 0 Jan 3, 2022
Simple library which enable you to add a drawer(slide-out) navigation to your android application

SimpleSideDrawer is an android library to add a drawer navigation into your android application. This library has high affinity with other libraries l

null 217 Nov 25, 2022
An Android Library that allows users to pull down a menu and select different actions. It can be implemented inside ScrollView, GridView, ListView.

AndroidPullMenu AndroidPullMenu is an Open Source Android library that allows developers to easily create applications with pull menu. The aim of this

Armando TBA 181 Nov 29, 2022
An Android library for managing multiple stacks of fragments

FragNav Android library for managing multiple stacks of fragments (e.g., Bottom Navigation , Navigation Drawer). This library does NOT include the UI

Nic Capdevila 1.5k Dec 26, 2022
A floating menu library for Android.

Hover Hover is a floating menu implementation for Android. Goals The goals of Hover are to: Provide an easy-to-use, out-of-the-box floating menu imple

Google 2.7k Dec 27, 2022
Spotify like android material bottom navigation bar library.

SuperBottomBar About Spotify like android material bottom navigation bar library. GIF Design Credits All design and inspiration credits belongs to Spo

Ertugrul 73 Dec 10, 2022
Suhuf is an android library that is used to build bottom sheets in an elegant way.

Suhuf is an android library that is used to build bottom sheets in an elegant way.

Rahmat Rasyidi Hakim 10 Nov 15, 2021
Neat library, that provides a simple way to implement guillotine-styled animation

Guillotine animation Neat library, that provides a simple way to implement guillotine-styled animation Check this [project on Dribbble] (https://dribb

Yalantis 2.7k Jan 3, 2023