Git Product home page Git Product logo

sidenavigation's Introduction

Android SideNavigation Library

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

Description

The Google+ app slides the navigation on top of the UI while the others move the UI to the side. Google+ also has the up caret icon and the action bar present when the menu is opened while other apps don't.

There was a interesting discussion about this pattern in the blog's Google+ page some time ago. You can find the post & discussion here: Google+.

Sample

A sample application is available on Google Play:

Get it on Google Play

Example Image Example Image

The source code is available in this repository.

Compatibility

This library is compatible from API 4 (Android 1.6).

Installation

The sample project requires:

Usage

To display the item you need the following code:

  • Add SideNavigationView to the end of the layout. Example:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/ic_android_logo" />

    <com.devspark.sidenavigation.SideNavigationView
        android:id="@+id/side_navigation_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>
  • Create '.xml' description of the menu for the sideNavigationView. Example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/side_navigation_menu_item1"
        android:icon="@drawable/ic_android1"
        android:title="@string/title1"/>
    <item
        android:id="@+id/side_navigation_menu_item2"
        android:icon="@drawable/ic_android2"
        android:title="@string/title2"/>
    <item
        android:id="@+id/side_navigation_menu_item3"
        android:icon="@drawable/ic_android3"
        android:title="@string/title3"/>
    <item
        android:id="@+id/side_navigation_menu_item4"
        android:icon="@drawable/ic_android4"
        android:title="@string/title4"/>
    <item
        android:id="@+id/side_navigation_menu_item5"
        android:icon="@drawable/ic_android5"
        android:title="@string/title5"/>

</menu>
  • Set home should be displayed as an "up" and initialize the sideNavigationView:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
    // other code
    
    sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view);
    sideNavigationView.setMenuItems(R.menu.side_navigation_menu);
	sideNavigationView.setMenuClickCallback(/*ISideNavigationCallback*/);
	sideNavigationView.setMode(/*SideNavigationView.Mode*/);
        
    getActionBar().setDisplayHomeAsUpEnabled(true);
}
  • Override onOptionsItemSelected() method for show/hide teh sideNavigationView:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
	case android.R.id.home:
		sideNavigationView.toggleMenu();
		break;
	default:
		return super.onOptionsItemSelected(item);
	}
	return true;
}
  • Implementation of ISideNavigationCallback:
ISideNavigationCallback sideNavigationCallback = new ISideNavigationCallback() {
    	
	@Override
	public void onSideNavigationItemClick(int itemId) {
		// Validation clicking on side navigation item
	}
};

Contribution

Please fork dev repository and contribute back using pull requests.

Contributors are recommended to follow the Android Code Style Guidelines.

Any contributions, large or small, major features, bug fixes, additional language translations, unit/integration tests are welcomed and appreciated but will be thoroughly reviewed and discussed.

Developed By

License

Copyright (C) 2012 Evgeny Shishkin

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.

sidenavigation's People

Contributors

johnkil avatar hram avatar

Watchers

James Cloos avatar Marlon Cepeda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.