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
Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.

Draggable Panel DEPRECATED. This project is not maintained anymore. Draggable Panel is an Android library created to build a draggable user interface

Pedro Vicente Gómez Sánchez 3k Dec 6, 2022
A beautiful Android custom View that works similar to a range or seekbar. With animations.

ValueBar A beautiful Android custom View that works similar to a range or seekbar. Selection by gesture. With animations. Supporting API level 11+. De

Philipp Jahoda 147 Nov 20, 2022
This library provides a simple way to add a draggable sliding up panel (popularized by Google Music and Google Maps) to your Android application. Brought to you by Umano.

Note: we are not actively responding to issues right now. If you find a bug, please submit a PR. Android Sliding Up Panel This library provides a simp

Umano: News Read To You 9.4k Dec 31, 2022
Android library to display a list of items for pick one

PickerUI Android library to display a list of items for pick one with blur effect (if you wish). Support for Android 3.0 and up. It supports portrait

David Pizarro 630 Nov 19, 2022
Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your development.

Bubbles for Android Bubbles for Android is an Android library to provide chat heads capabilities on your apps. With a fast way to integrate with your

Txus Ballesteros 1.5k Jan 2, 2023
Regret is an Android library for apps that wants to implement an undo/redo feature

Regret I've been developing on an editor for my Android App recently, using Jetpack Compose, but Google doesn't implement a built-in undo / redo for d

Moriafly 5 Jun 29, 2022
The ShowcaseView library is designed to highlight and showcase specific parts of apps to the user with an attractive and flat overlay.

The ShowcaseView library is designed to highlight and showcase specific parts of apps to the user with an attractive and flat overlay.

Mohammad Reza Eram 484 Dec 26, 2022
Android App that communicates with a back-end server to display different One Piece characters

About This project is an Android App that communicates with a back-end server to display different One Piece characters. It's roughly based on this co

Sam Garcia 1 Feb 4, 2022
Sentinel is a simple one screen UI which provides a standardised entry point for tools used in development and QA alongside device, application and permissions data.

Sentinel Sentinel is a simple one screen UI that provides standardised entry point for tools used in development and QA alongside device, application

Infinum 29 Dec 12, 2022
NeoPOP was created with one simple goal; to create the next generation of a beautiful, affirmative design system

NeoPop is CRED's inbuilt library for using NeoPop components in your app

CRED 254 Dec 29, 2022
[Deprecated] Android Library that implements Snackbars (former known as Undobar) from Google's Material Design documentation.

UndoBar This lib is deprecated in favor of Google's Design Support Library which includes a Snackbar and is no longer being developed. Thanks for all

Kai Liao 577 Nov 25, 2022
A View on which you can freely draw, customizing paint width, alpha and color, and take a screenshot of the content. Useful for note apps, signatures or free hand writing.

FreeDrawView A View that let you draw freely on it. You can customize paint width, alpha and color. Can be useful for notes app, signatures or hands-f

Riccardo Moro 643 Nov 28, 2022
Reach plc. Apps Team Exercise (Junior)

Reach plc. Apps Team Exercise (Junior) Description One of our magazines is looki

Paul Vickers 0 Dec 20, 2021
A simple launcher which displays all the apps on a RecyclerView trying to KISS

A simple launcher which displays all the apps on a RecyclerView trying to KISS

Alex Allafi 1 Jun 17, 2022
A skeleton of google's appcompat android navigation drawer with material design.

Lollipop AppCompat Skeleton A skeleton of google's appcompat android navigation drawer with material design. Compatible to work on 4.0+ Based on Googl

Sachin Shinde 99 Nov 29, 2022
Create an header for com.google.android.material.navigation.NavigationView

Header View This is a view for NavigationView in android.support.design library Import At the moment the library is in my personal maven repo reposito

Raphaël Bussa 106 Nov 25, 2022
Google Calendar Recurrence picker

Android Recurrence Picker Google Calendar Recurrence picker Screenshot Usage Maven / Gradle Maven: <dependency> <groupId>be.billington.calendar.recu

Benoit Billington 240 Nov 29, 2022
A new canvas drawing library for Android. Aims to be the Fabric.js for Android. Supports text, images, and hand/stylus drawing input. The library has a website and API docs, check it out

FabricView - A new canvas drawing library for Android. The library was born as part of a project in SD Hacks (www.sdhacks.io) on October 3rd. It is cu

Antwan Gaggi 1k Dec 13, 2022
Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. The library is based on the code of Mario Klingemann.

Android StackBlur Android StackBlur is a library that can perform a blurry effect on a Bitmap based on a gradient or radius, and return the result. Th

Enrique López Mañas 3.6k Dec 29, 2022