GithubHelp home page GithubHelp logo

ekyawthan / material-drawer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from heinrichreimer/material-drawer

0.0 2.0 0.0 358 KB

Custom drawer implementation for Material design apps.

License: Apache License 2.0

Java 100.00%

material-drawer's Introduction

material-drawer

Android Arsenal

Custom drawer implementation for Material design apps.

How-To-Use

Step 1: Include it in your layout:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawerLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    
    <com.heinrichreimersoftware.materialdrawer.DrawerView
        android:id="@+id/drawer"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"/>

</android.support.v4.widget.DrawerLayout>

Step 2: Find views:

DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
DrawerView drawer = (DrawerView) findViewById(R.id.drawer);

Step 3: Set a profile:

drawer.setProfile(
        new DrawerProfile()
                .setAvatar(getResources().getDrawable(R.drawable.profile_avatar))
                .setBackground(getResources().getDrawable(R.drawable.profile_background))
                .setName(getString(R.string.profile_name))
                .setDescription(getString(R.string.profile_description))
                .setOnProfileClickListener(new DrawerProfile.OnProfileClickListener() {
                    @Override
                    public void onClick(DrawerProfile drawerProfile) {
                        Toast.makeText(YourActivity.this, "Clicked profile", Toast.LENGTH_SHORT).show();
                    }
                })
        );

Step 4: Populate your drawer list:

drawer.addItem(
        new DrawerItem()
                .setImage(getResources().getDrawable(R.drawable.ic_first_item))
                .setTextPrimary(getString(R.string.title_first_item))
                .setTextSecondary(getString(R.string.description_first_item))
                .setOnItemClickListener(new DrawerItem.OnItemClickListener() {
                    @Override
                    public void onClick(DrawerItem drawerItem, int id, int position) {
                        Toast.makeText(YourActivity.this, "Clicked first item (#" + id + ")", Toast.LENGTH_SHORT).show();
                    }
                })
        );
drawer.addDivider();
drawer.addItem(
        new DrawerItem()
                .setImage(getResources().getDrawable(R.drawable.ic_second_item))
                .setTextPrimary(getString(R.string.title_second_item))
                .setOnItemClickListener(new DrawerItem.OnItemClickListener() {
                    @Override
                    public void onClick(DrawerItem drawerItem, ind id, int position) {
                        Toast.makeText(YourActivity.this, "Clicked second item (#" + id + ")", Toast.LENGTH_SHORT).show();
                    }
                })
        );

Tip: Lollipop status bar

Step 1: Add fitSystemWindows="true" to your DrawerLayout and your DrawerView in XML.

Step 2: Set custom status bar color for your DrawerLayout:

drawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.your_chosen_color));

Step 3: Use Toolbar instead of ActionBar.

Step 4: Make your status bar transparent:

<style name="Theme.MyApp" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
</style>

That's it! material-drawer takes care of the rest.

For further information see Chris Banes' answer on stackoverflow.com.

Dependency

material-drawer is available on Maven Central

Gradle dependency:

dependencies {
    compile 'com.heinrichreimersoftware.materialdrawer:library:1.2'
}

Get the latest dependency with "Gradle, please"

Changes

  • Version 1.2:
    • Drawer items can now contain an ID
    • Image setters work with Bitmap too
  • Version 1.1.1:
    • You can change items that you got via drawer.getItem(position). Changes will update the adapter
    • Fixed auto drawer width
    • Fixed title padding

Open source libraries

material-drawer uses the following open source libraries or files:

License

Copyright 2013 Heinrich Reimer

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.

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.