Create an header for com.google.android.material.navigation.NavigationView

Overview

Header View

Download Android Arsenal

Logo

This is a view for NavigationView in android.support.design library

Import

At the moment the library is in my personal maven repo

repositories {
    maven {
        url 'http://dl.bintray.com/raphaelbussa/maven'
    }
}
dependencies {
    implementation 'rebus:header-view:3.0.2'
}

How to use

Via XML

Create a layout named like this header_drawer.xml

<rebus.header.view.HeaderView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/header_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:hv_add_icon="@drawable/ic_action_settings"
    app:hv_add_status_bar_height="true"
    app:hv_background_color="@color/colorPrimaryDark"
    app:hv_dialog_title="@string/account"
    app:hv_highlight_color="@color/colorAccent"
    app:hv_profile_avatar="@drawable/ic_placeholder"
    app:hv_profile_background="@drawable/ic_placeholder_bg"
    app:hv_profile_email="[email protected]"
    app:hv_profile_username="Bruce Wayne"
    app:hv_show_add_button="true"
    app:hv_show_arrow="true"
    app:hv_show_gradient="true"
    app:hv_style="normal"
    app:hv_theme="light" />

And in your NavigationView

<android.support.design.widget.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/header_drawer"
    app:menu="@menu/drawer" />

Manage Profiles

The new HeaderView manage different profile and a new profile chooser inspired from YouTube android app

  • Create a profile
Profile profile = new Profile.Builder()
        .setId(2)
        .setUsername("Raphaël Bussa")
        .setEmail("[email protected]")
        .setAvatar("https://github.com/rebus007.png?size=512")
        .setBackground("https://images.unsplash.com/photo-1473220464492-452fb02e6221?dpr=2&auto=format&fit=crop&w=767&h=512&q=80&cs=tinysrgb&crop=")
        .build();
  • Add a profile
headerView.addProfile(profile);
  • Set a profile active
headerView.setProfileActive(2);
  • Remove a profile
headerView.removeProfile(2);
  • Get actual active profile
int activeProfileId = headerView.getProfileActive();

Customize Profile Chooser

You can also customize the profile chooser

  • Add bottom items
Item item = new Item.Builder()
        .setId(1)
        .setTitle("Remove all profile")
        .build();

headerView.addDialogItem(item);
  • HighlightColor in dialog
headerView.setHighlightColor(ContextCompat.getColor(this, R.color.colorAccent));
app:hv_highlight_color="@color/colorAccent"
  • Change dialog title
headerView.setDialogTitle("Choose account");
app:hv_dialog_title="Dialog title"
  • Change dialog top icon
headerView.setAddIconDrawable(R.drawable.ic_action_settings);
app:hv_add_icon="@drawable/ic_action_settings"
  • Or hide dialog top icon
headerView.setShowAddButton(true);
app:hv_show_add_button="true"
  • Dismiss profile chooser dialog
headerView.dismissProfileChooser();

Callback

headerView.setCallback(new HeaderCallback() {

    @Override
    public boolean onSelect(int id, boolean isActive) {
        //return profile id selected and if is the active profile
        return true; //true for close the dialog, false for do nothing
    }

    @Override
    public boolean onItem(int id) {
        //return witch buttom item is selected
        return true; //true for close the dialog, false for do nothing
    }

    @Override
    public boolean onAdd() {
        return true; //true for close the dialog, false for do nothing
    }
});

Loading image from network

Just add this in your class Application (of course you can use your preferred libs for load images)

ImageLoader.init(new ImageLoader.ImageLoaderInterface() {
    @Override
    public void loadImage(Uri url, ImageView imageView, @ImageLoader.Type int type) {
        switch (type) {
            case ImageLoader.AVATAR:
                Glide.with(imageView.getContext())
                        .load(url)
                        .asBitmap()
                        .placeholder(R.drawable.ic_placeholder)
                        .error(R.drawable.ic_placeholder)
                        .into(imageView);
                break;
             case ImageLoader.HEADER:
                Glide.with(imageView.getContext())
                        .load(url)
                        .asBitmap()
                        .placeholder(R.drawable.ic_placeholder_bg)
                        .error(R.drawable.ic_placeholder_bg)
                        .into(imageView);
                break;
        }
    }

});

Use custom font with Calligraphy

You can set a custom font with Calligraphy just add a CustomViewTypeface with HeaderView.class in CalligraphyConfig

CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
        .setDefaultFontPath("Oswald-Stencbab.ttf")
        .setFontAttrId(R.attr.fontPath)
        .addCustomViewWithSetTypeface(HeaderView.class)
        .build()
);

Screen

Screen

Sample

Browse the sample code here or download sample app from the Play Store

Javadoc

Browse Javadoc here

App using Header View

If you use this lib contact me and I will add it to the list below:

Developed By

Raphaël Bussa - [email protected]

Twitter Linkedin

License

The MIT License (MIT)

Copyright (c) 2017 Raphaël Bussa <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Comments
  • Add license scan report and status

    Add license scan report and status

    Your FOSSA integration was successful! Attached in this PR is a badge and license report to track scan status in your README.

    Below are docs for integrating FOSSA license checks into your CI:

    opened by fossabot 1
  • fix onRestoreInstance sparseArray null

    fix onRestoreInstance sparseArray null

    Chrash log:

    Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int android.util.SparseArray.size()' on a null object reference at rebus.header.view.HeaderView.populateAvatar + 395(HeaderView.java:395) at rebus.header.view.HeaderView.onRestoreInstanceState + 795(HeaderView.java:795) at android.view.View.dispatchRestoreInstanceState + 17819(View.java:17819) at android.view.ViewGroup.dispatchRestoreInstanceState + 3773(ViewGroup.java:3773) at android.view.ViewGroup.dispatchRestoreInstanceState + 3781(ViewGroup.java:3781) at android.view.View.restoreHierarchyState + 17797(View.java:17797) at com.google.android.material.internal.NavigationMenuPresenter.onRestoreInstanceState + 192(NavigationMenuPresenter.java:192) at androidx.appcompat.view.menu.MenuBuilder.dispatchRestoreInstanceState + 363(MenuBuilder.java:363) at androidx.appcompat.view.menu.MenuBuilder.restorePresenterStates + 375(MenuBuilder.java:375) at com.google.android.material.navigation.NavigationView.onRestoreInstanceState + 216(NavigationView.java:216) at android.view.View.dispatchRestoreInstanceState + 17819(View.java:17819) at android.view.ViewGroup.dispatchRestoreInstanceState + 3773(ViewGroup.java:3773) at android.view.ViewGroup.dispatchRestoreInstanceState + 3781(ViewGroup.java:3781) at android.view.ViewGroup.dispatchRestoreInstanceState + 3781(ViewGroup.java:3781) at android.view.ViewGroup.dispatchRestoreInstanceState + 3781(ViewGroup.java:3781) at android.view.ViewGroup.dispatchRestoreInstanceState + 3781(ViewGroup.java:3781) at android.view.View.restoreHierarchyState + 17797(View.java:17797) at com.android.internal.policy.PhoneWindow.restoreHierarchyState + 2255(PhoneWindow.java:2255) at android.app.Activity.onRestoreInstanceState + 1198(Activity.java:1198) at android.app.Activity.performRestoreInstanceState + 1152(Activity.java:1152) at android.app.Instrumentation.callActivityOnRestoreInstanceState + 1264(Instrumentation.java:1264) at android.app.ActivityThread.performLaunchActivity + 3270(ActivityThread.java:3270) at android.app.ActivityThread.handleLaunchActivity + 3405(ActivityThread.java:3405) at android.app.ActivityThread.-wrap12() at android.app.ActivityThread$H.handleMessage + 1994(ActivityThread.java:1994) at android.os.Handler.dispatchMessage + 108(Handler.java:108) at android.os.Looper.loop + 166(Looper.java:166) at android.app.ActivityThread.main + 7523(ActivityThread.java:7523) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.Zygote$MethodAndArgsCaller.run + 245(Zygote.java:245) at com.android.internal.os.ZygoteInit.main + 921(ZygoteInit.java:921)

    opened by RurioLuca 0
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    rebus007/HeaderView now has a Chat Room on Gitter

    @rebus007 has just created a chat room. You can visit it here: https://gitter.im/rebus007/HeaderView.

    This pull-request adds this badge to your README.md:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 0
  • When the Activity is recycled HeaderView will get an error

    When the Activity is recycled HeaderView will get an error

    @raphaelbussa When the Activity is recycled HeaderView will get an error.

        java.lang.ClassCastException: java.lang.String cannot be cast to android.net.Uri
            at rebus.header.view.Profile.<init>(Profile.java:82)
            at rebus.header.view.Profile.<init>(Profile.java:46)
            at rebus.header.view.Profile$1.createFromParcel(Profile.java:51)
            at rebus.header.view.Profile$1.createFromParcel(Profile.java:48)
            at android.os.Parcel.readParcelable(Parcel.java:2774)
            at android.os.Parcel.readValue(Parcel.java:2668)
            at android.os.Parcel.readSparseArrayInternal(Parcel.java:3118)
            at android.os.Parcel.readSparseArray(Parcel.java:2351)
            at android.os.Parcel.readValue(Parcel.java:2725)
            at android.os.Parcel.readArrayMapInternal(Parcel.java:3037)
            at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:288)
            at android.os.BaseBundle.unparcel(BaseBundle.java:232)
            at android.os.Bundle.getParcelable(Bundle.java:940)
            at rebus.header.view.HeaderView.onRestoreInstanceState(HeaderView.java:793)
            at android.view.View.dispatchRestoreInstanceState(View.java:18608)
            at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3821)
            at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
            at android.view.View.restoreHierarchyState(View.java:18586)
            at com.google.android.material.internal.NavigationMenuPresenter.onRestoreInstanceState(NavigationMenuPresenter.java:192)
            at androidx.appcompat.view.menu.MenuBuilder.dispatchRestoreInstanceState(MenuBuilder.java:363)
            at androidx.appcompat.view.menu.MenuBuilder.restorePresenterStates(MenuBuilder.java:375)
            at com.google.android.material.navigation.NavigationView.onRestoreInstanceState(NavigationView.java:216)
            at android.view.View.dispatchRestoreInstanceState(View.java:18608)
            at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3821)
            at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
            at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
            at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
            at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:3827)
            at android.view.View.restoreHierarchyState(View.java:18586)
            at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2135)
            at android.app.Activity.onRestoreInstanceState(Activity.java:1135)
            at android.app.Activity.performRestoreInstanceState(Activity.java:1090)
            at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1317)
            at android.app.ActivityThread.handleStartActivity(ActivityThread.java:2991)
            at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
            at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
            at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
            at android.os.Handler.dispatchMessage(Handler.java:106)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:6718)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
    

    Turn this option on under the developer option to test. image

    opened by tcqq 1
  • Conflict with circleimageview dependency

    Conflict with circleimageview dependency

    @raphaelbussa

    Duplicate class de.hdodenhof.circleimageview.CircleImageView found in modules classes.jar (de.hdodenhof:circleimageview:3.0.1) and classes.jar (rebus:header-view:3.0.3)
    Duplicate class de.hdodenhof.circleimageview.CircleImageView$1 found in modules classes.jar (de.hdodenhof:circleimageview:3.0.1) and classes.jar (rebus:header-view:3.0.3)
    Duplicate class de.hdodenhof.circleimageview.CircleImageView$OutlineProvider found in modules classes.jar (de.hdodenhof:circleimageview:3.0.1) and classes.jar (rebus:header-view:3.0.3)
    
    
    opened by tcqq 0
Releases(3.0.0)
Owner
Raphaël Bussa
Senior Android Developer. Open source lover. European citizen.
Raphaël Bussa
Bottom Sheet fragment with a sticky header and a content recycler view

Sticky Header Bottom Sheet A simple library to create a Bottom Sheet with a sticky header and a content recycler view. The bottom sheet expands on scr

Kshitij Kumar 12 Sep 21, 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
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
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
Android - Blur Navigation Drawer like Etsy app.

Blur Navigation Drawer Library[DEPRECATED] Blur Navigation Drawer like Etsy app. Demo You can download a demo here. Updates Version 1.1 Add support fo

Vasilis Charalampakis 414 Nov 23, 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 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
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
A new way to implement navigation in your app 🏎

ExpandableBottomBar A new way to improve navigation in your app Its really easy integrate to your project take it, faster, faster Important: library w

Alexander Dadukin 692 Dec 29, 2022
A customizable and easy to use BottomBar navigation view with sleek animations, with support for ViewPager, ViewPager2, NavController, and badges.

AnimatedBottomBar A customizable and easy to use bottom bar view with sleek animations. Examples Playground app Download the playground app from Googl

Joery 1.2k Dec 30, 2022
A simple Floating Action Button that shows an anchored Navigation View

Floating Navigation View A simple Floating Action Button that shows an anchored Navigation View and was inspired by Menu Material Fixed created by Tom

André Mion 1.3k Dec 29, 2022
You can create awesome menus with bottom sheet experience in a few lines

You can create awesome menus with bottom sheet experience in a few lines

Mazen Rashed 19 Nov 1, 2022
An app that helps you create & remove WSA icon in the start menu

WSA Helper An application that allows you to manager WSA's icons in start menus

LSPosed 142 Dec 24, 2022
Android Library for a DrawerLayout similar to the one in Google Apps

GoogleNavigationDrawerMenu This project aims to let you use a ListView menu similar to the one in the new Google Apps (Keep, Play Music...) without ha

Jorge Martin Espinosa 267 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
:fire: The powerful and easiest way to implement modern material popup menu.

PowerMenu ?? The powerful and easiest way to implement modern material popup menu. PowerMenu can be fully customized and used for popup dialogs. Downl

Jaewoong Eum 1k Dec 29, 2022