You might have noticed that lot of android applications introduced a sliding panel menu to navigate between major modules of the application. Previously this kind of UI was done using some third party libraries where a list view and some swiping gestures used to achieve this. But now android itself officially introduced sliding panel menu by introducing a newer concept called Navigation Drawer in which we combine DrawerLayout and NavigationView to achieve the desired output.

Most of the time Sliding Menu (Navigation Drawer) will be hidden and can be shown by swiping the screen from left edge to right or tapping the app icon on the action bar.

android navigation drawer slider menu

Example Applications

You can see lot of popular applications like Facebook, Youtube, Google + already introduced navigation drawer menu in their applications. Following are the navigation drawer menus of multiple apps.

android navigation drawer facebook, google plus, youtube

1. Android Studio Navigation Drawer Template

You can add Navigation Drawer in your app in two ways. The quick and easy way is choosing the Navigation Drawer Activity from Android Studio when the new project is created. This creates an empty project with navigation drawer added.

android-navigation-drawer-android-studio

This creates the below basic skeleton app with few navigation menu items.

android-navigation-drawer-activity

Even though Android Studio gives you basic Navigation Drawer Menu, making it fully functional takes some effort. The next steps explains how to customize the navigation drawer appearance by adding header image, profile image and other texts. You will also learn how to prepare and attach the other menu views by creating the fragments and loading them properly.

To give you full information about navigation drawer, instead of choosing the drawer temple, I am creating an empty project and add the navigation drawer by explaining every step is needed. So let’s get started.

Below is the final output we are going to achieve in this article.

android-navigation-drawer-menu

2. Starting new Project

1. Create a new project in Android Studio from File ⇒ New Project by filling the required details. When it prompts you to select the activity, choose Empty Activity and continue.

2. Open build.gradle located in app level and add below dependencies. I am adding Glide image library dependency. This is not needed for navigation drawer, but to load the profile image from url.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.0.0-beta1'
    compile 'com.android.support:design:24.0.0-beta1'
    compile 'com.android.support:support-v4:24.0.0-beta1'

    // Glide image library
    compile 'com.github.bumptech.glide:glide:3.7.0'
}

3. Open strings.xml, dimens.xml, colors.xml located under res ⇒ values and add the below values.

<resources>
    <string name="app_name">Navigation Drawer</string>

    <string name="navigation_drawer_open">Open navigation drawer</string>
    <string name="navigation_drawer_close">Close navigation drawer</string>
    <string name="openDrawer">open_drawer</string>
    <string name="closeDrawer">close_drawer</string>

    <!-- Navigation Drawer menu labels -->
    <string name="nav_home">Home</string>
    <string name="nav_photos">Photos</string>
    <string name="nav_movies">Movies</string>
    <string name="nav_notifications">Notifications</string>
    <string name="nav_settings">Settings</string>
    <string name="nav_about_us">About Us</string>

    <!-- Toolbar titles when navigation menu item is selected -->
    <string-array name="nav_item_activity_titles">
        <item>Home</item>
        <item>Photos</item>
        <item>Movies</item>
        <item>Notifications</item>
        <item>Settings</item>
    </string-array>

    <string name="activity_title_about_us">About Us</string>
    <string name="activity_title_privacy_policy">Privacy Policy</string>
    <string name="action_clear_all">Clear All</string>
    <string name="action_logout">Logout</string>
    <string name="action_mark_all_read">Mark All as Read</string>
    <string name="privacy_policy">Privacy Policy</string>
</resources>
<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="nav_header_vertical_spacing">16dp</dimen>
    <dimen name="nav_header_height">160dp</dimen>

    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="fab_margin">16dp</dimen>
    <dimen name="profile_width">75dp</dimen>
    <dimen name="profile_height">75dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#d32f2f</color>
    <color name="colorPrimaryDark">#c72c2c</color>
    <color name="colorAccent">#FFFFFF</color>
</resources>

4. Download Home, Photos, Movies, Notifications, Settings icons from Material Icons and add them to your project’s res folder. These icons will be used as navigation menu item icons.

5. Under res ⇒ menu directory, create two menu xml files named notifications.xml and main.xml. These menus are used to render different toolbar overflow menus when the user switches between navigation drawer items.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_mark_all_read"
        android:orderInCategory="100"
        android:title="@string/action_mark_all_read"
        app:showAsAction="never" />

    <item
        android:id="@+id/action_clear_notifications"
        android:orderInCategory="101"
        android:title="@string/action_clear_all"
        app:showAsAction="never" />
</menu>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/action_logout"
        android:orderInCategory="100"
        android:title="@string/action_logout"
        app:showAsAction="never" />
</menu>

Creating Fragments & Activities

6. Create three packages named activity, fragment, other and move the MainActivity.java to activity package.

7. Create all the fragment classes needed for navigation menu. Overall I am creating five fragment classes. Right click on fragment package, New ⇒ Fragment ⇒ Fragment (Blank) and name it as HomeFragment.java. This fragment will be loaded always whenever user open the app.

Likewise create other fragment activities named PhotosFragment, MoviesFragment, NotificationsFragment and SettingsFragment.

8. In our navigation drawer menu, there are two other menu items, About Us and Privacy Policy. For these two we are gonna create activities instead of fragments. Create new two activities named AboutUsActivity.java and PrivacyPolicyActivity.java.

android-navigation-drawer-project-structure

9. Inside other package, create a class named CircleTransform.java This class is used to display the profile image in circular fashion.

package info.androidhive.navigationdrawer.other;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

/**
 * Created by Lincoln on 10/03/16.
 */
public class CircleTransform extends BitmapTransformation {
    public CircleTransform(Context context) {
        super(context);
    }

    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
        return circleCrop(pool, toTransform);
    }

    private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
        if (source == null) return null;

        int size = Math.min(source.getWidth(), source.getHeight());
        int x = (source.getWidth() - size) / 2;
        int y = (source.getHeight() - size) / 2;

        // TODO this could be acquired from the pool too
        Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

        Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
        if (result == null) {
            result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
        }

        Canvas canvas = new Canvas(result);
        Paint paint = new Paint();
        paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
        paint.setAntiAlias(true);
        float r = size / 2f;
        canvas.drawCircle(r, r, r, paint);
        return result;
    }

    @Override
    public String getId() {
        return getClass().getName();
    }
}

10. Under res ⇒ drawable, create a file named bg_circle.xml. This provides circular background to view.

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid
        android:color="@color/colorPrimary"/>

    <size
        android:width="120dp"
        android:height="120dp"/>
</shape>

11. Under res layout folder, create a layout named menu_dot.xml. This layout is used to render dot next to notifications label.

android-navigation-drawer-action-view

Adding Navigation Drawer

12. Under res ⇒ menu directory, create a menu xml file named activity_main_drawer.xml. This menu renders the Navigation Drawer list items. Here we set the icons and labels. You can also notice here <group> is used to combine multiple items under single levels. An <item> also can be used group multiple child items with a title. This provides a horizontal separator between the two sets.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <group android:checkableBehavior="single">
        <item
            android:id="@+id/nav_home"
            android:icon="@drawable/ic_home_black_24dp"
            android:title="@string/nav_home" />
        <item
            android:id="@+id/nav_photos"
            android:icon="@drawable/ic_photo_library_black_24dp"
            android:title="@string/nav_photos" />
        <item
            android:id="@+id/nav_movies"
            android:icon="@drawable/ic_local_movies_black_24dp"
            android:title="@string/nav_movies" />

        <item
            android:id="@+id/nav_notifications"
            android:icon="@drawable/ic_notifications_black_24dp"
            android:title="@string/nav_notifications" />

        <item
            android:id="@+id/nav_settings"
            android:icon="@drawable/ic_settings_black_24dp"
            android:title="@string/nav_settings" />
    </group>

    <item android:title="Other">
        <menu>
            <item
                android:id="@+id/nav_about_us"
                android:title="@string/nav_about_us" />
            <item
                android:id="@+id/nav_privacy_policy"
                android:title="@string/privacy_policy" />
        </menu>
    </item>

</menu>

13. Under res ⇒ layout, create a file named nav_header_main.xml This layout renders the navigation drawer header part with a profile image, name and website.

14. Now we’ll create another layout file to add required Toolbar, FAB and FrameLayout. FrameLayout is used to load appropriate fragment when an item is selected from nav menu. Create a layout file named app_bar_main.xml under res ⇒ layout.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="info.androidhive.navigationdrawer.activity.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"></FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        app:backgroundTint="@color/colorPrimary"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

15. Open the layout file your main activity activity_main.xml and add NavigationView element. You can notice that the toolbar layout is added using <include> tag.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

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

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

16. Now we have all the required elements in place. It’s time to open the main activity and do the necessary changes to make the navigation drawer functional. Open MainActivity.java and modify as explained below.

setUpNavigationView() – Initializes the Navigation Drawer by creating necessary click listeners and other functions.

loadNavHeader() – Function loads the navigation drawer header information like profile image, name and website. Here we use Glide image library to load the profile image.

getHomeFragment() – Returns the appropriate Fragment depending on the nav menu item user selected. For example if user selects Photos from nav menu, it returns PhotosFragment. This can be done by using the variable navItemIndex.

loadHomeFragment() – Loads the fragment returned from getHomeFragment() function into FrameLayout. It also takes care of other things like changing the toolbar title, hiding / showing fab, invalidating the options menu so that new menu can be loaded for different fragment.

Other code is very easy to understand and self explanatory. I have also added comments to each code block for better understanding.

package info.androidhive.navigationdrawer.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import info.androidhive.navigationdrawer.R;
import info.androidhive.navigationdrawer.fragment.HomeFragment;
import info.androidhive.navigationdrawer.fragment.MoviesFragment;
import info.androidhive.navigationdrawer.fragment.NotificationsFragment;
import info.androidhive.navigationdrawer.fragment.PhotosFragment;
import info.androidhive.navigationdrawer.fragment.SettingsFragment;
import info.androidhive.navigationdrawer.other.CircleTransform;

public class MainActivity extends AppCompatActivity {

    private NavigationView navigationView;
    private DrawerLayout drawer;
    private View navHeader;
    private ImageView imgNavHeaderBg, imgProfile;
    private TextView txtName, txtWebsite;
    private Toolbar toolbar;
    private FloatingActionButton fab;

    // urls to load navigation header background image
    // and profile image
    private static final String urlNavHeaderBg = "https://api.androidhive.info/images/nav-menu-header-bg.jpg";
    private static final String urlProfileImg = "https://lh3.googleusercontent.com/eCtE_G34M9ygdkmOpYvCag1vBARCmZwnVS6rS5t4JLzJ6QgQSBquM0nuTsCpLhYbKljoyS-txg";

    // index to identify current nav menu item
    public static int navItemIndex = 0;

    // tags used to attach the fragments
    private static final String TAG_HOME = "home";
    private static final String TAG_PHOTOS = "photos";
    private static final String TAG_MOVIES = "movies";
    private static final String TAG_NOTIFICATIONS = "notifications";
    private static final String TAG_SETTINGS = "settings";
    public static String CURRENT_TAG = TAG_HOME;

    // toolbar titles respected to selected nav menu item
    private String[] activityTitles;

    // flag to load home fragment when user presses back key
    private boolean shouldLoadHomeFragOnBackPress = true;
    private Handler mHandler;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mHandler = new Handler();

        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        navigationView = (NavigationView) findViewById(R.id.nav_view);
        fab = (FloatingActionButton) findViewById(R.id.fab);

        // Navigation view header
        navHeader = navigationView.getHeaderView(0);
        txtName = (TextView) navHeader.findViewById(R.id.name);
        txtWebsite = (TextView) navHeader.findViewById(R.id.website);
        imgNavHeaderBg = (ImageView) navHeader.findViewById(R.id.img_header_bg);
        imgProfile = (ImageView) navHeader.findViewById(R.id.img_profile);

        // load toolbar titles from string resources
        activityTitles = getResources().getStringArray(R.array.nav_item_activity_titles);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        // load nav menu header data
        loadNavHeader();

        // initializing navigation menu
        setUpNavigationView();

        if (savedInstanceState == null) {
            navItemIndex = 0;
            CURRENT_TAG = TAG_HOME;
            loadHomeFragment();
        }
    }

    /***
     * Load navigation menu header information
     * like background image, profile image
     * name, website, notifications action view (dot)
     */
    private void loadNavHeader() {
        // name, website
        txtName.setText("Ravi Tamada");
        txtWebsite.setText("www.androidhive.info");

        // loading header background image
        Glide.with(this).load(urlNavHeaderBg)
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imgNavHeaderBg);

        // Loading profile image
        Glide.with(this).load(urlProfileImg)
                .crossFade()
                .thumbnail(0.5f)
                .bitmapTransform(new CircleTransform(this))
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(imgProfile);

        // showing dot next to notifications label
        navigationView.getMenu().getItem(3).setActionView(R.layout.menu_dot);
    }

    /***
     * Returns respected fragment that user
     * selected from navigation menu
     */
    private void loadHomeFragment() {
        // selecting appropriate nav menu item
        selectNavMenu();

        // set toolbar title
        setToolbarTitle();

        // if user select the current navigation menu again, don't do anything
        // just close the navigation drawer
        if (getSupportFragmentManager().findFragmentByTag(CURRENT_TAG) != null) {
            drawer.closeDrawers();

            // show or hide the fab button
            toggleFab();
            return;
        }

        // Sometimes, when fragment has huge data, screen seems hanging
        // when switching between navigation menus
        // So using runnable, the fragment is loaded with cross fade effect
        // This effect can be seen in GMail app
        Runnable mPendingRunnable = new Runnable() {
            @Override
            public void run() {
                // update the main content by replacing fragments
                Fragment fragment = getHomeFragment();
                FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                fragmentTransaction.setCustomAnimations(android.R.anim.fade_in,
                        android.R.anim.fade_out);
                fragmentTransaction.replace(R.id.frame, fragment, CURRENT_TAG);
                fragmentTransaction.commitAllowingStateLoss();
            }
        };

        // If mPendingRunnable is not null, then add to the message queue
        if (mPendingRunnable != null) {
            mHandler.post(mPendingRunnable);
        }

        // show or hide the fab button
        toggleFab();

        //Closing drawer on item click
        drawer.closeDrawers();

        // refresh toolbar menu
        invalidateOptionsMenu();
    }

    private Fragment getHomeFragment() {
        switch (navItemIndex) {
            case 0:
                // home
                HomeFragment homeFragment = new HomeFragment();
                return homeFragment;
            case 1:
                // photos
                PhotosFragment photosFragment = new PhotosFragment();
                return photosFragment;
            case 2:
                // movies fragment
                MoviesFragment moviesFragment = new MoviesFragment();
                return moviesFragment;
            case 3:
                // notifications fragment
                NotificationsFragment notificationsFragment = new NotificationsFragment();
                return notificationsFragment;

            case 4:
                // settings fragment
                SettingsFragment settingsFragment = new SettingsFragment();
                return settingsFragment;
            default:
                return new HomeFragment();
        }
    }

    private void setToolbarTitle() {
        getSupportActionBar().setTitle(activityTitles[navItemIndex]);
    }

    private void selectNavMenu() {
        navigationView.getMenu().getItem(navItemIndex).setChecked(true);
    }

    private void setUpNavigationView() {
        //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu
        navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

            // This method will trigger on item Click of navigation menu
            @Override
            public boolean onNavigationItemSelected(MenuItem menuItem) {

                //Check to see which item was being clicked and perform appropriate action
                switch (menuItem.getItemId()) {
                    //Replacing the main content with ContentFragment Which is our Inbox View;
                    case R.id.nav_home:
                        navItemIndex = 0;
                        CURRENT_TAG = TAG_HOME;
                        break;
                    case R.id.nav_photos:
                        navItemIndex = 1;
                        CURRENT_TAG = TAG_PHOTOS;
                        break;
                    case R.id.nav_movies:
                        navItemIndex = 2;
                        CURRENT_TAG = TAG_MOVIES;
                        break;
                    case R.id.nav_notifications:
                        navItemIndex = 3;
                        CURRENT_TAG = TAG_NOTIFICATIONS;
                        break;
                    case R.id.nav_settings:
                        navItemIndex = 4;
                        CURRENT_TAG = TAG_SETTINGS;
                        break;
                    case R.id.nav_about_us:
                        // launch new intent instead of loading fragment
                        startActivity(new Intent(MainActivity.this, AboutUsActivity.class));
                        drawer.closeDrawers();
                        return true;
                    case R.id.nav_privacy_policy:
                        // launch new intent instead of loading fragment
                        startActivity(new Intent(MainActivity.this, PrivacyPolicyActivity.class));
                        drawer.closeDrawers();
                        return true;
                    default:
                        navItemIndex = 0;
                }

                //Checking if the item is in checked state or not, if not make it in checked state
                if (menuItem.isChecked()) {
                    menuItem.setChecked(false);
                } else {
                    menuItem.setChecked(true);
                }
                menuItem.setChecked(true);

                loadHomeFragment();

                return true;
            }
        });


        ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.openDrawer, R.string.closeDrawer) {

            @Override
            public void onDrawerClosed(View drawerView) {
                // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
                super.onDrawerClosed(drawerView);
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank
                super.onDrawerOpened(drawerView);
            }
        };

        //Setting the actionbarToggle to drawer layout
        drawer.setDrawerListener(actionBarDrawerToggle);

        //calling sync state is necessary or else your hamburger icon wont show up
        actionBarDrawerToggle.syncState();
    }

    @Override
    public void onBackPressed() {
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawers();
            return;
        }

        // This code loads home fragment when back key is pressed
        // when user is in other fragment than home
        if (shouldLoadHomeFragOnBackPress) {
            // checking if user is on other navigation menu
            // rather than home
            if (navItemIndex != 0) {
                navItemIndex = 0;
                CURRENT_TAG = TAG_HOME;
                loadHomeFragment();
                return;
            }
        }

        super.onBackPressed();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.

        // show menu only when home fragment is selected
        if (navItemIndex == 0) {
            getMenuInflater().inflate(R.menu.main, menu);
        }

        // when fragment is notifications, load the menu created for notifications
        if (navItemIndex == 3) {
            getMenuInflater().inflate(R.menu.notifications, menu);
        }
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_logout) {
            Toast.makeText(getApplicationContext(), "Logout user!", Toast.LENGTH_LONG).show();
            return true;
        }

        // user is in notifications fragment
        // and selected 'Mark all as Read'
        if (id == R.id.action_mark_all_read) {
            Toast.makeText(getApplicationContext(), "All notifications marked as read!", Toast.LENGTH_LONG).show();
        }

        // user is in notifications fragment
        // and selected 'Clear All'
        if (id == R.id.action_clear_notifications) {
            Toast.makeText(getApplicationContext(), "Clear all notifications!", Toast.LENGTH_LONG).show();
        }

        return super.onOptionsItemSelected(item);
    }

    // show or hide the fab
    private void toggleFab() {
        if (navItemIndex == 0)
            fab.show();
        else
            fab.hide();
    }
}

Run and test the app once. You should able to see the app as shown below. Also check the Video demo of fully implemented navigation drawer.

android-navigation-drawer-menu
Subscribe
Notify of
guest
1614 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mamro Kirill
Mamro Kirill
7 years ago

Perfect example. Thank you.
And how to make a more sophisticated style of a picture in G+ for example?

Ravi Tamada
7 years ago
Reply to  Mamro Kirill

You mean to change it to white color or adding an image above listview ?

Gaurav Mahajan
Gaurav Mahajan
7 years ago
Reply to  Ravi Tamada

how can we change the g+ icon?

Gaurav Mahajan
Gaurav Mahajan
7 years ago
Reply to  Gaurav Mahajan

I think, its same as application icon. ic_launcher.png

Ravi Tamada
7 years ago
Reply to  Gaurav Mahajan

Yes

Salman Shah
Salman Shah
6 years ago
Reply to  Ravi Tamada

hey Ravi Please tell us about header??

prabhakar
prabhakar
6 years ago
Reply to  Ravi Tamada

Hello Ravi,

I am trying to implement this code but Activity not started

the logcat show following error

07-26 06:13:41.167: E/AndroidRuntime(2219): FATAL EXCEPTION: main

07-26 06:13:41.167: E/AndroidRuntime(2219): Process: com.easy.menu, PID: 2219

07-26 06:13:41.167: E/AndroidRuntime(2219): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.easy.menu/com.easy.menu.MainActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class android.widget.ListView

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.app.ActivityThread.access$800(ActivityThread.java:135)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.os.Handler.dispatchMessage(Handler.java:102)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.os.Looper.loop(Looper.java:136)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.app.ActivityThread.main(ActivityThread.java:5017)

07-26 06:13:41.167: E/AndroidRuntime(2219): at java.lang.reflect.Method.invokeNative(Native Method)

07-26 06:13:41.167: E/AndroidRuntime(2219): at java.lang.reflect.Method.invoke(Method.java:515)

07-26 06:13:41.167: E/AndroidRuntime(2219): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)

07-26 06:13:41.167: E/AndroidRuntime(2219): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)

07-26 06:13:41.167: E/AndroidRuntime(2219): at dalvik.system.NativeStart.main(Native Method)

07-26 06:13:41.167: E/AndroidRuntime(2219): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class android.widget.ListView

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.view.LayoutInflater.createView(LayoutInflater.java:620)

07-26 06:13:41.167: E/AndroidRuntime(2219): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)

07-26 06:13:41.167: E/AndroidRuntime(2219): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.app.Activity.setContentView(Activity.java:1929)

07-26 06:13:41.167: E/AndroidRuntime(2219): at com.easy.menu.MainActivity.onCreate(MainActivity.java:46)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.app.Activity.performCreate(Activity.java:5231)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)

07-26 06:13:41.167: E/AndroidRuntime(2219): … 11 more

07-26 06:13:41.167: E/AndroidRuntime(2219): Caused by: java.lang.reflect.InvocationTargetException

07-26 06:13:41.167: E/AndroidRuntime(2219): at java.lang.reflect.Constructor.constructNative(Native Method)

07-26 06:13:41.167: E/AndroidRuntime(2219): at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.view.LayoutInflater.createView(LayoutInflater.java:594)

07-26 06:13:41.167: E/AndroidRuntime(2219): … 24 more

07-26 06:13:41.167: E/AndroidRuntime(2219): Caused by: android.content.res.Resources$NotFoundException: File res/color/primary_text_dark.xml from drawable resource ID #0x1060001

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.content.res.Resources.loadDrawable(Resources.java:2096)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.content.res.TypedArray.getDrawable(TypedArray.java:602)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.widget.ListView.(ListView.java:158)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.widget.ListView.(ListView.java:142)

07-26 06:13:41.167: E/AndroidRuntime(2219): … 27 more

07-26 06:13:41.167: E/AndroidRuntime(2219): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #18: tag requires a ‘drawable’ attribute or child tag defining a drawable

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:181)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)

07-26 06:13:41.167: E/AndroidRuntime(2219): at android.content.res.Resources.loadDrawable(Resources.java:2092)

07-26 06:13:41.167: E/AndroidRuntime(2219): … 30 more

please help how to solve this.
Thank You:)

Anas Sahri
7 years ago

Thanks very much i need this tutorial to continue my application

Ravi Tamada
7 years ago
Reply to  Anas Sahri

You are welcome 🙂

Anas Sahri
7 years ago
Reply to  Ravi Tamada

i wana another tutorial if possible
how to upload my picture from android to my Server with PHP
Thanks man

Ravi Tamada
7 years ago
Reply to  Anas Sahri

I already prepared a project, but the problem is it is not uploading more than 2MB file. I am still figuring out the solution.

Anas Sahri
7 years ago
Reply to  Ravi Tamada

Thanks man
I’m waiting this tutorial

Roger Miret
7 years ago
Reply to  Ravi Tamada

Ravi, check that this 2MB restriction is not due to PHP’s configuration (ie. php.ini).

(PS: I’ve sent you a tutorial request. I must hand a highschool project on december and a tutorial on SSH connections in Android apps would help me a lot!)

Ravi Tamada
7 years ago
Reply to  Roger Miret

Hi Xaic,

The problem is not on serverside. It is on client side. Getting memory exceptions …

Roger Miret
7 years ago
Reply to  Ravi Tamada

Hi Ravi. In case you want the full image to be uploaded I don’t know how to help. However, if you don’t mind on the image resolution I propose reducing the image before sending it to the server.

Ravi Tamada
7 years ago
Reply to  Roger Miret

Yeah, good suggestion in case of Image upload. But we need to consider the case of uploading video to server or some zip file.

Ramiz Mohamed
Ramiz Mohamed
7 years ago

Nice post, Ravi.

Ravi Tamada
7 years ago
Reply to  Ramiz Mohamed

Thank You Ramiz 🙂

Yogesh
Yogesh
7 years ago

Thank you for the post. It really helps you out. I just have one question, is there a way we can make it work with a custom sliding menu like https://github.com/jfeinstein10/SlidingMenu, can you just look into it.

Thanks.

Mahmudul
Mahmudul
7 years ago

Nice post. Like it!!!

chandan
chandan
7 years ago

This is one of the most awaited post.. Loved it 🙂

Anh Tuan
Anh Tuan
7 years ago

Great. But how do it run on API 8 ( Android 2.2 ). Current Project is :
android:minSdkVersion=”11″
android:targetSdkVersion=”17″

Ravi Tamada
7 years ago
Reply to  Anh Tuan

You can do it using Support Library – http://developer.android.com/tools/support-library/index.html

Anh Tuan
Anh Tuan
7 years ago
Reply to  Ravi Tamada

Thank you.

Hue Nguyen
Hue Nguyen
7 years ago

First, thanks for your tutorial, I have tested your demo but there is an occasional error when dragging menu appears only a part and not the whole show Menu.

Ravi Tamada
7 years ago
Reply to  Hue Nguyen

Please provide me the details on which device/os version you testing it on.

Hue Nguyen
Hue Nguyen
7 years ago
Reply to  Ravi Tamada

i run on android 4.1.1 (memopad – asus).

screenshot: http://awesomescreenshot.com/0871yahec7

Gaurav Mahajan
Gaurav Mahajan
7 years ago

Thanks for posing this. very nice.

Radhakrishnan
Radhakrishnan
7 years ago

nice tutorial ..androidhive you rocks always

Ravi Tamada
7 years ago
Reply to  Radhakrishnan

Yeah androidhive rocks 🙂

amay
amay
7 years ago

Hai ravi, i want run it on API 8 ( Android 2.2 ), i have using Support Library with add android-support-v4.jar in folder jar , in manifest i am change android:minSdkVersion=”8″ , but it still force close . how to fix it ?

Ravi Tamada
7 years ago
Reply to  amay

Debug the errors and tell me what is the error you are getting. (Use Logcat to see the errors)

amay
amay
7 years ago
Reply to  Ravi Tamada

11-14 15:03:42.524: I/dalvikvm(299): Could not find method info.androidhive.slidingmenu.MainActivity.getFragmentManager, referenced from method info.androidhive.slidingmenu.MainActivity.displayView

11-14 15:03:42.524: W/dalvikvm(299): VFY: unable to resolve virtual method 4636: Linfo/androidhive/slidingmenu/MainActivity;.getFragmentManager ()Landroid/app/FragmentManager;

11-14 15:03:42.524: D/dalvikvm(299): VFY: replacing opcode 0x6e at 0x0006

11-14 15:03:42.534: W/dalvikvm(299): Unable to resolve superclass of Linfo/androidhive/slidingmenu/HomeFragment; (12)

11-14 15:03:42.534: W/dalvikvm(299): Link of class ‘Linfo/androidhive/slidingmenu/HomeFragment;’ failed

11-14 15:03:42.534: E/dalvikvm(299): Could not find class ‘info.androidhive.slidingmenu.HomeFragment’, referenced from method info.androidhive.slidingmenu.MainActivity.displayView

11-14 15:03:42.534: W/dalvikvm(299): VFY: unable to resolve new-instance 638 (Linfo/androidhive/slidingmenu/HomeFragment;) in Linfo/androidhive/slidingmenu/MainActivity;

11-14 15:03:42.534: D/dalvikvm(299): VFY: replacing opcode 0x22 at 0x0032

11-14 15:03:42.534: W/dalvikvm(299): Unable to resolve superclass of Linfo/androidhive/slidingmenu/FindPeopleFragment; (12)

11-14 15:03:42.534: W/dalvikvm(299): Link of class ‘Linfo/androidhive/slidingmenu/FindPeopleFragment;’ failed

11-14 15:03:42.534: E/dalvikvm(299): Could not find class ‘info.androidhive.slidingmenu.FindPeopleFragment’, referenced from method info.androidhive.slidingmenu.MainActivity.displayView

11-14 15:03:42.534: W/dalvikvm(299): VFY: unable to resolve new-instance 637 (Linfo/androidhive/slidingmenu/FindPeopleFragment;) in Linfo/androidhive/slidingmenu/MainActivity;

11-14 15:03:42.534: D/dalvikvm(299): VFY: replacing opcode 0x22 at 0x0038

11-14 15:03:42.544: W/dalvikvm(299): Unable to resolve superclass of Linfo/androidhive/slidingmenu/PhotosFragment; (12)

11-14 15:03:42.544: W/dalvikvm(299): Link of class ‘Linfo/androidhive/slidingmenu/PhotosFragment;’ failed

11-14 15:03:42.544: E/dalvikvm(299): Could not find class ‘info.androidhive.slidingmenu.PhotosFragment’, referenced from method info.androidhive.slidingmenu.MainActivity.displayView

11-14 15:03:42.544: W/dalvikvm(299): VFY: unable to resolve new-instance 643 (Linfo/androidhive/slidingmenu/PhotosFragment;) in Linfo/androidhive/slidingmenu/MainActivity;

11-14 15:03:42.544: D/dalvikvm(299): VFY: replacing opcode 0x22 at 0x003e

11-14 15:03:42.554: W/dalvikvm(299): Unable to resolve superclass of Linfo/androidhive/slidingmenu/CommunityFragment; (12)

11-14 15:03:42.554: W/dalvikvm(299): Link of class ‘Linfo/androidhive/slidingmenu/CommunityFragment;’ failed

11-14 15:03:42.554: E/dalvikvm(299): Could not find class ‘info.androidhive.slidingmenu.CommunityFragment’, referenced from method info.androidhive.slidingmenu.MainActivity.displayView

11-14 15:03:42.564: W/dalvikvm(299): VFY: unable to resolve new-instance 636 (Linfo/androidhive/slidingmenu/CommunityFragment;) in Linfo/androidhive/slidingmenu/MainActivity;

11-14 15:03:42.564: D/dalvikvm(299): VFY: replacing opcode 0x22 at 0x0044

11-14 15:03:42.564: W/dalvikvm(299): Unable to resolve superclass of Linfo/androidhive/slidingmenu/PagesFragment; (12)

11-14 15:03:42.564: W/dalvikvm(299): Link of class ‘Linfo/androidhive/slidingmenu/PagesFragment;’ failed

11-14 15:03:42.574: E/dalvikvm(299): Could not find class ‘info.androidhive.slidingmenu.PagesFragment’, referenced from method info.androidhive.slidingmenu.MainActivity.displayView

11-14 15:03:42.574: W/dalvikvm(299): VFY: unable to resolve new-instance 642 (Linfo/androidhive/slidingmenu/PagesFragment;) in Linfo/androidhive/slidingmenu/MainActivity;

11-14 15:03:42.574: D/dalvikvm(299): VFY: replacing opcode 0x22 at 0x004a

11-14 15:03:42.584: W/dalvikvm(299): Unable to resolve superclass of Linfo/androidhive/slidingmenu/WhatsHotFragment; (12)

11-14 15:03:42.584: W/dalvikvm(299): Link of class ‘Linfo/androidhive/slidingmenu/WhatsHotFragment;’ failed

11-14 15:03:42.584: E/dalvikvm(299): Could not find class ‘info.androidhive.slidingmenu.WhatsHotFragment’, referenced from method info.androidhive.slidingmenu.MainActivity.displayView

11-14 15:03:42.584: W/dalvikvm(299): VFY: unable to resolve new-instance 655 (Linfo/androidhive/slidingmenu/WhatsHotFragment;) in Linfo/androidhive/slidingmenu/MainActivity;

11-14 15:03:42.584: D/dalvikvm(299): VFY: replacing opcode 0x22 at 0x0050

11-14 15:03:42.584: D/dalvikvm(299): VFY: dead code 0x0009-0030 in Linfo/androidhive/slidingmenu/MainActivity;.displayView (I)V

11-14 15:03:42.584: D/dalvikvm(299): VFY: dead code 0x0034-0037 in Linfo/androidhive/slidingmenu/MainActivity;.displayView (I)V

11-14 15:03:42.594: D/dalvikvm(299): VFY: dead code 0x003a-003d in Linfo/androidhive/slidingmenu/MainActivity;.displayView (I)V

11-14 15:03:42.594: D/dalvikvm(299): VFY: dead code 0x0040-0043 in Linfo/androidhive/slidingmenu/MainActivity;.displayView (I)V

11-14 15:03:42.594: D/dalvikvm(299): VFY: dead code 0x0046-0049 in Linfo/androidhive/slidingmenu/MainActivity;.displayView (I)V

11-14 15:03:42.594: D/dalvikvm(299): VFY: dead code 0x004c-004f in Linfo/androidhive/slidingmenu/MainActivity;.displayView (I)V

11-14 15:03:42.594: D/dalvikvm(299): VFY: dead code 0x0052-0055 in Linfo/androidhive/slidingmenu/MainActivity;.displayView (I)V

11-14 15:03:42.614: I/dalvikvm(299): Could not find method info.androidhive.slidingmenu.MainActivity.getActionBar, referenced from method info.androidhive.slidingmenu.MainActivity.onCreate

11-14 15:03:42.624: W/dalvikvm(299): VFY: unable to resolve virtual method 4634: Linfo/androidhive/slidingmenu/MainActivity;.getActionBar ()Landroid/app/ActionBar;

11-14 15:03:42.624: D/dalvikvm(299): VFY: replacing opcode 0x6e at 0x00ee

11-14 15:03:42.624: D/dalvikvm(299): VFY: dead code 0x00f1-011a in Linfo/androidhive/slidingmenu/MainActivity;.onCreate (Landroid/os/Bundle;)V

11-14 15:03:42.634: I/dalvikvm(299): Could not find method info.androidhive.slidingmenu.MainActivity.getActionBar, referenced from method info.androidhive.slidingmenu.MainActivity.setTitle

11-14 15:03:42.634: W/dalvikvm(299): VFY: unable to resolve virtual method 4634: Linfo/androidhive/slidingmenu/MainActivity;.getActionBar ()Landroid/app/ActionBar;

11-14 15:03:42.634: D/dalvikvm(299): VFY: replacing opcode 0x6e at 0x0002

11-14 15:03:42.634: D/dalvikvm(299): VFY: dead code 0x0005-000b in Linfo/androidhive/slidingmenu/MainActivity;.setTitle (Ljava/lang/CharSequence;)V

11-14 15:03:42.764: D/AndroidRuntime(299): Shutting down VM

11-14 15:03:42.764: W/dalvikvm(299): threadid=1: thread exiting with uncaught exception (group=0x4001d800)

11-14 15:03:42.784: E/AndroidRuntime(299): FATAL EXCEPTION: main

11-14 15:03:42.784: E/AndroidRuntime(299): java.lang.NoSuchMethodError: info.androidhive.slidingmenu.MainActivity.getActionBar

11-14 15:03:42.784: E/AndroidRuntime(299): at info.androidhive.slidingmenu.MainActivity.onCreate(MainActivity.java:86)

11-14 15:03:42.784: E/AndroidRuntime(299): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

11-14 15:03:42.784: E/AndroidRuntime(299): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

11-14 15:03:42.784: E/AndroidRuntime(299): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)

11-14 15:03:42.784: E/AndroidRuntime(299): at android.app.ActivityThread.access$2300(ActivityThread.java:125)

11-14 15:03:42.784: E/AndroidRuntime(299): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)

11-14 15:03:42.784: E/AndroidRuntime(299): at android.os.Handler.dispatchMessage(Handler.java:99)

11-14 15:03:42.784: E/AndroidRuntime(299): at android.os.Looper.loop(Looper.java:123)

11-14 15:03:42.784: E/AndroidRuntime(299): at android.app.ActivityThread.main(ActivityThread.java:4627)

11-14 15:03:42.784: E/AndroidRuntime(299): at java.lang.reflect.Method.invokeNative(Native Method)

11-14 15:03:42.784: E/AndroidRuntime(299): at java.lang.reflect.Method.invoke(Method.java:521)

11-14 15:03:42.784: E/AndroidRuntime(299): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)

11-14 15:03:42.784: E/AndroidRuntime(299): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)

11-14 15:03:42.784: E/AndroidRuntime(299): at dalvik.system.NativeStart.main(Native Method)

Ravi Tamada
7 years ago
Reply to  amay

While using the Support Library you need to change lot of methods.

Use getSupportFragmentManager() instead of getFragmentManager()

Also use getSupportActionBar() you should use getActionBar()

imelyaa
imelyaa
7 years ago

hy ravi. like the others , I still can’t run this project (Android 2.3) although I was using support Library , this is my logcat , thanks 🙂

11-14 14:06:42.000: E/AndroidRuntime(22980): FATAL EXCEPTION: main

11-14 14:06:42.000: E/AndroidRuntime(22980): java.lang.NoSuchMethodError: info.androidhive.slidingmenu.MainActivity.getActionBar

11-14 14:06:42.000: E/AndroidRuntime(22980): at info.androidhive.slidingmenu.MainActivity.onCreate(MainActivity.java:87)

11-14 14:06:42.000: E/AndroidRuntime(22980): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

11-14 14:06:42.000: E/AndroidRuntime(22980): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)

11-14 14:06:42.000: E/AndroidRuntime(22980): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)

11-14 14:06:42.000: E/AndroidRuntime(22980): at android.app.ActivityThread.access$1500(ActivityThread.java:117)

11-14 14:06:42.000: E/AndroidRuntime(22980): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)

11-14 14:06:42.000: E/AndroidRuntime(22980): at android.os.Handler.dispatchMessage(Handler.java:99)

11-14 14:06:42.000: E/AndroidRuntime(22980): at android.os.Looper.loop(Looper.java:130)

11-14 14:06:42.000: E/AndroidRuntime(22980): at android.app.ActivityThread.main(ActivityThread.java:3687)

11-14 14:06:42.000: E/AndroidRuntime(22980): at java.lang.reflect.Method.invokeNative(Native Method)

11-14 14:06:42.000: E/AndroidRuntime(22980): at java.lang.reflect.Method.invoke(Method.java:507)

11-14 14:06:42.000: E/AndroidRuntime(22980): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)

11-14 14:06:42.000: E/AndroidRuntime(22980): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)

11-14 14:06:42.000: E/AndroidRuntime(22980): at dalvik.system.NativeStart.main(Native Method)

Ravi Tamada
7 years ago
Reply to  imelyaa

Hi Imelyaa,

You are using support library, instead of calling getActionBar() you should use getSupportActionBar()

ranjithstar256
ranjithstar256
6 years ago
Reply to  Ravi Tamada

ravi bro for me when i use getsupportActionBar() it is showing, the method getsupportActionBar() is definded for the type MainActivity… What should i do bro??

Firos
Firos
7 years ago
Reply to  imelyaa

sir, i need tutorial for simple chat app like whatsApp. pls help me.

ShahNawaz Khan
ShahNawaz Khan
7 years ago
Reply to  imelyaa

2.3 doesn’t support actionbar, checkout actionbar sherlock library

Dennis Drzosga
Dennis Drzosga
7 years ago

HI Ravi,
it is possile to call a second sliding menu on the right side, if call for example the PhotosFragment to select a folder or something, if yes can you tell me how.

Ravi
Ravi
7 years ago

Hey Ravi,
Thanks for this post… i was looking for this tutorial from a long time now finally got it from you but i am not able to run it on 2.3 when i change min and target sdk version to 7 and 19 respectively i get error and wont be able to run project ..please help me …..

Ravi Tamada
7 years ago
Reply to  Ravi

Give me the error you are getting ?

Guest
Guest
7 years ago
Reply to  Ravi Tamada

if i am compile with android api 17 and higher it is working fine but whenever i compile it with lower version i.e. on 2.3 i get exception(No such Method) on getactionbar() method in main activity

Ravi
Ravi
7 years ago
Reply to  Ravi Tamada

i am getting exception on getActionBar method (No Such Method).I am using support library but didn’t find any method like getSupportActionBar()

Ravi
Ravi
7 years ago
Reply to  Ravi Tamada

i have changed mainactivity extend to fragmentactivity instead of activity class but cant find method getsupprortactionbar . i am getting arror “aapt.exe” encountered a problem

javadroid
javadroid
7 years ago
Reply to  Ravi

i think you use android.fragment instead android.support.v4.fragment

Ravi
Ravi
7 years ago
Reply to  javadroid

but android.fragment doesn’t work on API lower than 11 i want it to compatible with on 2.1 and 2.3 too…

javadroid
javadroid
7 years ago

thanks Ravi,
it was so useful 🙂

zeeshan
zeeshan
7 years ago

great work Ravi, keep it up 🙂

EL Benderradji Kheireddine
EL Benderradji Kheireddine
7 years ago

great job dude !

Sithu
Sithu
7 years ago

Thanks Ravi

Alexiel
Alexiel
7 years ago

Many thanks for your good work!

Kittu
Kittu
7 years ago

Hey Ravi, great tutorial, I am looking for an expandable sliding menu, I have tried to implement an expandable listview in place of your basic listview but could not get the solution. Any help will be much appretiated

Ravi Tamada
7 years ago
Reply to  Kittu
Kittu
Kittu
7 years ago
Reply to  Ravi Tamada

Yeh, the error says that an expandable listview is not allowed inside drawer layout

Salman Shah
Salman Shah
6 years ago
Reply to  Ravi Tamada

Hi Ravi Thanks for this Nice Tutorial..
Now we have a problem to put header or title so to categorize the list…but we dont know how to do it….i spent a whole week on search on how to add header to this list view but failed…Some other guys also ask the same question before but you didn’t reply for that..please help us on how to add header to the list view in this source??
Thanks once again for such a nice Tutorial

Trollzito
Trollzito
7 years ago

Excelente i love you!! yeahhh!!! fuck

Sweet.Misery
Sweet.Misery
7 years ago

Guys…honestly you have the best tutorials over the internet. they were really usefull for me.
I love U so much. wish you bests.

Ravi Tamada
7 years ago
Reply to  Sweet.Misery

Thank you so much Misery … 🙂

Ravi
Ravi
7 years ago

Please upload code which is compatible with 2.3 too. I will be thankful to you….

Firos
Firos
7 years ago

i need tutorial for simple chat app like whatsApp. pls help me.

Ravi Tamada
7 years ago
Reply to  Firos

Yeah, It is under progress. But I have to complete some dependency articles before it publishes. That’s why postponed.

Mohammad
Mohammad
7 years ago

Your website is really great!
I do not know anything about databases in android, thanks for the link I’m about to tell me, or like the recent training on a comprehensive Explained database android do
Translation by Google

Ravi Tamada
7 years ago
Reply to  Mohammad

You can learn these to get an idea about database in android
http://www.androidhive.info/category/sqlite/

Koda
Koda
7 years ago

Great tutorial! but how do you take off the 22 and 50+?

Ravi Tamada
7 years ago
Reply to  Koda

In MainActiivty.java look for this comment // Communities, Will add a counter here

Ravi T.
Ravi T.
7 years ago

Please upload code which is compatible with 2.3 too. I will be thankful to you….

Deva
Deva
7 years ago

Hi Ravi,
Thanks for this tutorial,

how to refresh the counter value dynamically, do i need to call the web service every time when the sliding menu is brought to front.

Ravi Tamada
7 years ago
Reply to  Deva

You can do that but I recommend you to use push notification. This way you don’t have to call service every time. Whenever update is there in the server, you will get notification, using this you can update counter value.

Now how to update counter value is, update the row in the array adapter which is used for list view. And call
notifyDataSetChanged() on the adapter. This will automatically update the listview.

Deva Karthik
Deva Karthik
7 years ago
Reply to  Ravi Tamada

Thanks Ravi for your quick reply, believe GCM will the right candidate here for push notification.
can you please share your views on jeremyfeinstein sliding menu?

Ravi Tamada
7 years ago
Reply to  Deva Karthik

Hi Karthik, Yeah you can GCM for this. Sorry I haven’t worked with jeremyfeinstein sliding menu.

Max
Max
7 years ago

Great tutorial !
I have one question ! Why don’t you use activities instead of fragments ? I mean HomeFragment could be HomeAcitivity, etc…

Ravi Tamada
7 years ago
Reply to  Max

Fragments is the best way to replace a view. You can’t replace a view if you use activity.

Raj
Raj
7 years ago

Hi Ravi,

Nice tutorial so thank you so much. Now I have a question that If I want to add a bottom bar as we have action bar at top in this example.I have added a bottom bar at bottom by adding a layout. but I am facing a problem i.e my bottom bar slides with fragments. I want to make it static as we have static action bar(without sliding). so please tell me how I can I achieve it. Thanks

Ravi Tamada
7 years ago
Reply to  Raj

Hi Raj, using navigation drawer with tabs is not suggested way. However you can do it in another way. Create another layout and include the Navigation drawer layout and bottom tab layout using a relative layout. You can use tag for this.

Also this guy suggested how to overlap tabs on navigation drawer
http://kriomant.blogspot.com/2013/08/navigation-drawer-tabs-overlap.html

Sumeet Raj
Sumeet Raj
7 years ago

Thanks Ravi for this nice tutorial..

James Graham
James Graham
7 years ago

Hi Ravi, awesome tutorial.

Just one issue, I’m getting an issue with the screenshot below. Can you help?
comment image

Thanks

James Graham
James Graham
7 years ago
Reply to  Ravi Tamada

Absolute superstar. Something I simply missed at the top of the code. Slap hand across forehead. Been looking to implement the sliding drawer and all the tutorials I have found have not been anywhere near as good as yours. Much Kudos to you Ravi

Ravi Tamada
7 years ago
Reply to  James Graham

Thanks for the appreciation James 🙂

قلب الأمل
قلب الأمل
7 years ago

Hi there,
Thanks for the tutorial

but I have question, how can Implement the onClick button that is in the “FindPeople.xml” for example I tried to implement it in the “FindPeople.class” but didn’t work and tried to implement it in the MainActivity and works fine.

the big question is it efficient to implement all “onClick” events for all pages in the MainActivity?? I don’t really prefer it

and how can I implement it in the Fragment java file for each page??
Hope you understand my question

thanks a lot

Ravi Tamada
7 years ago

It should work. Could you post your code, how you did it

قلب الأمل
قلب الأمل
7 years ago
Reply to  Ravi Tamada

I solved the problem ^_^
Thanks a lot ^_^

Pranav Mahajan
Pranav Mahajan
7 years ago

How did u solve it. I’m having the same problem. Say if I have a button in each fragment , then would I need to declare their methods in MainActivity.java , because they are not visible in Fragment classes.

قلب الأمل
قلب الأمل
7 years ago
Reply to  Pranav Mahajan

Hi Pranav.
you can declare the buttons in your fragment class
do the following:

1. Declare the Button variable as a public variable in the class so that you can use it in any method.
(write this code after the class name:
Button your_button_name;)

2. inside the “onCreateView” method write:
a. set the layout:
View rootView = inflater.inflate(R.layout.your_fragment_layout, container, false);

b. initiate the button:
your_button_name = (Button) rootView.findViewById(R.id.button_id);

c. set the onClick listener:
your_button_name.setOnClickListener(this);

3. Override a method called “onClick” and let the class implements “OnClickListener”.the following code is implemented to handle a click listener event for more than one button:

@Override
public void onClick(View view) {
/* This method to deal with multiple buttons
if the class has only one button then write the
code to handle the on click button event directly
here*/

switch (view.getId()) {
case R.id.btn_search_submit: // write your button id
Search(); /* method to handle the event when
this button is clicked*/
break;
case R.id.btn_category:
Category();
break;
case R.id.btn_where_to_search:
Where_to_search();
break;
}
}

Hope you find my solution clear
All the Best ^_^

Pranav Mahajan
Pranav Mahajan
7 years ago

It worked..thanks…
but I have another conceptual question… I was trying to do this by declaring android:onclick = “hello” in the XML file
I had to declare the corresponding hello() function in MainActivity.java . It was’nt visible from the Fragment class. Can you explain me the difference between the 2 approaches to define button listener.

قلب الأمل
قلب الأمل
7 years ago
Reply to  Pranav Mahajan

Actually I tried the same way as you. then I tried to do it another way. that is how I solved the problem ^_^. I don’t know what is the difference ^_^

Rupesh
Rupesh
7 years ago

Hi Ravi,
Thanks for the tutorial
But I have Question,how can Implement the slider menu open the current activity also moving how can implement this type of code please help me.

Ravi Tamada
7 years ago
Reply to  Rupesh

This kind of navigation is there previously. But android.com is not suggesting this way. You can see Google+, Youtube modified their application already.

Rupesh
Rupesh
7 years ago
Reply to  Ravi Tamada

Thanks Ravi,Any code availble this type project please send the link.

gunawan
gunawan
7 years ago

Hi Ravi, Good Tutorial. I try your code, I have Question, in “home” fragment im using webview to load website, i try using refresh on Action Bar to reload webview on fragment.

Here is my code :

public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_refresh:
// refresh

refreshMenuItem = item;

// load the data from server
new SyncData().execute();
return true;
case R.id.action_settings:
Intent intent = new Intent(this, Setting.class);
this.startActivity(intent);
break;

default:
return super.onOptionsItemSelected(item);
}
return false;
}

On case R.id.action_refresh: what the code to use to reload webview. Sorry im newbie and sorry for bad english.

SeeZa
SeeZa
7 years ago

nICE Tutorial Ravi. do you recommend using activities instead of fragments? or does the drawer support use of activities?

Rishil
Rishil
7 years ago

Hey Ravi,

Awesome tutorial.
I have two questions.
1) I don’t want to display the counter in my silder menu..I tried to remove it but it lead me to unexpected behavior.
2) I am having two classes which extend activity. I need to open them when I click on respective list item. Is that possible ?

Thanks in advance.

Ravi Tamada
7 years ago
Reply to  Rishil

Yeah you can do it. When you add list item in adapter like

navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), false, “22”)); – pass false here or don’t pass anything. It won’t display a counter.

Vivek Ravi
Vivek Ravi
7 years ago

Hi Ravi
Thanks for your nice tutorial. But on item click is not working for me.

Ravi Tamada
7 years ago
Reply to  Vivek Ravi

Did you called this line mDrawerList.setOnItemClickListener(….) in main activity?

Vivek Ravi
Vivek Ravi
7 years ago
Reply to  Ravi Tamada

Ok Ravi. I solved that issue. Thanks for your help…

Thinh Ng
Thinh Ng
7 years ago

Hi Ravi, thanks for your example!
I have a question, how to easy implement header section for navigation item?

Disk Jokey Adi
Disk Jokey Adi
7 years ago

Awesome tutorial!!
i have a question, how to add title, image and email from url like the example image above???

harsh
harsh
7 years ago

import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
these lines r shwing error..i have also copied android support library in the libs folder of the project,,plz help!!

Kiitens
Kiitens
7 years ago
Reply to  harsh

having the same problem here, any tips will be great, thanks!

Ravi Tamada
7 years ago
Reply to  harsh

After copying it to libs folder, did you link the jar in project properties?

Dhanraj
Dhanraj
7 years ago

I need to create a file manager with navigation drawer, but i’m unable to inflate the list view for the file manager in the framelayout using fragment. Help appreciated

Pranav Mahajan
Pranav Mahajan
7 years ago

Hi Ravi, absolutely brilliant!!
Q- What if I have a button in each fragment. I’ll have to declare all of their listeners in MainActivity.java. That is wrong in any design . How do I resolve this issue??

If I start a new activity(TempActivity extends MainActivity) in the “switch clause” instead of replacing the fragments,then replace the Fragment from the TempActivity, then there are performances issues. Also, the sliding animations go away. Thanks in advance..

Ravi Tamada
7 years ago
Reply to  Pranav Mahajan

Hi Pranav, lot people asking about listener problem in fragments. I’ll have to look into it once. I haven’t tried yet.

Pranav Mahajan
Pranav Mahajan
7 years ago
Reply to  Ravi Tamada

I’ve figured a solution.

In my fragment classes I use button = (Button)rootView.findViewById(R.id.button1);
& then declare its listener…This works

But, instead if I try android:onclick=”hello”, then I have to declare the corresponding hello() function in MainActivity.java, then it becomes messy…

Can you tell me the difference between the 2 implementations of the button listeners I’ve mentioned above

Arthur
Arthur
7 years ago

Hey Ravi, you have some of the best tutorials on the net 🙂

A question, there’s an issue with the native android drawer and i wonder if you have found a solution for it. If you use more than simple text and a small icon in the drawer fragments then the transactions lag a bit. E.g Try to add big images to each fragment, the drawer transactions will lag

Neo
Neo
7 years ago

Hi Ravi,

could you possibly add a guide regarding how to add a seperator listview like youtube apps did?

Regards

Neo
Neo
7 years ago
Reply to  Neo

and sub description under each listview attributes? regards

Droid Developer
Droid Developer
6 years ago

Ravi, Please upload in app purchase demo . I am waiting for a tutorial of this from your side. Please upload it as soon as possible as it is essential feature these days.

Raj
Raj
6 years ago

Hi Ravi,

Thanks for quick reply and suggestion. I am not using tabs but a simple view which does not have any component on it. I have a problem related to drawer i.e when I launched main activity then it takes about 2 to 3 seconds to become visible(screen goes blank).I have placed all the code into the onResume() because I thought that due to large code in onCreate() it is taking more time than usual. but It did not solve my problem. I am in big trouble and also tried so many ways to reduce this time but could not succeeded. so please help me what am I doing wrong…

Kleon
Kleon
6 years ago

amazing tutorial!
Can you please provide a solution with headers / sections?

Akshay Taru
Akshay Taru
6 years ago

Does it support 2.3?

Rishil
Rishil
6 years ago
Reply to  Akshay Taru

I also tried on my 2.3.4 version phone…Application is crashing.

:disqus : What changes do we need to do to make it work on 2.3 ?

I changed minsdk version to 9. Still not working.

Thanks.

Akshay Taru
Akshay Taru
6 years ago
Reply to  Rishil

Remove android:background=”@drawable/list_selector” from drawer_list_selector.xml it should work. There is bug log for this in library.

Rishil
Rishil
6 years ago
Reply to  Akshay Taru

You mean drawer_list_item.xml ??

Akshay Taru
Akshay Taru
6 years ago
Reply to  Rishil

yes drawer_list_item.xml sorry for typo, Remove that attribute and the app should work.

Rishil
Rishil
6 years ago
Reply to  Akshay Taru

I removed android:background=”@drawable/list_selector” from drawer_list_item.xml..

Still not working on my 2.3.4.. 🙁

Akshay Taru
Akshay Taru
6 years ago
Reply to  Rishil
Ravi Tamada
6 years ago
Reply to  Rishil

Changing the minsdk to 9 won’t work. You need to include Support Library and have to do changes in code too. Like when using getActionBar(), you should call getSupportActionBar().

Rishil
Rishil
6 years ago
Reply to  Ravi Tamada

Please provide reference URL for the same if available.
As I haven’t used it, I don’t know the exact steps.

I have imported import android.support.v4.app.Fragment;

Thanks

Guest
Guest
6 years ago
Reply to  Rishil

package info.androidhive.slidingmenu;

import info.androidhive.slidingmenu.adapter.NavDrawerListAdapter;
import info.androidhive.slidingmenu.model.NavDrawerItem;

import java.util.ArrayList;

import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class MainActivity extends FragmentActivity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;

// nav drawer title
private CharSequence mDrawerTitle;

// used to store app title
private CharSequence mTitle;

// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;

private ArrayList navDrawerItems;
private NavDrawerListAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mTitle = mDrawerTitle = getTitle();

// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

// nav drawer icons from resources
navMenuIcons = getResources()
.obtainTypedArray(R.array.nav_drawer_icons);

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

navDrawerItems = new ArrayList();

// adding nav drawer items to array
// Home
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
// Find People
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
// Photos
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
// Communities, Will add a counter here
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
// Pages
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
// What’s hot, We will add a counter here
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));

// Recycle the typed array
navMenuIcons.recycle();

mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

// setting the nav drawer list adapter
adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);
mDrawerList.setAdapter(adapter);

// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, //nav menu toggle icon
R.string.app_name, // nav drawer open – description for accessibility
R.string.app_name // nav drawer close – description for accessibility
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}

public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);

if (savedInstanceState == null) {
// on first time display view for first nav item
displayView(0);
}
}

/**
* Slide menu item click listener
* */
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_settings:
return true;
default:
return super.onOptionsItemSelected(item);
}
}

/* *
* Called when invalidateOptionsMenu() is triggered
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}

/**
* Diplaying fragment view for selected nav drawer list item
* */
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
case 0:
fragment = new HomeFragment();
break;
case 1:
fragment = new FindPeopleFragment();
break;
case 2:
fragment = new PhotosFragment();
break;
case 3:
fragment = new CommunityFragment();
break;
case 4:
fragment = new PagesFragment();
break;
case 5:
fragment = new WhatsHotFragment();
break;

default:
break;
}

if (fragment != null) {
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();

// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
// error in creating fragment
Log.e(“MainActivity”, “Error in creating fragment”);
}
}

@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}

/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()…
*/

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}

}

Sami M.
Sami M.
6 years ago
Reply to  Akshay Taru

Hi Akshay,

As
it is right now it supports only API level 14 (Android 4.0) and + . But you can
“leveldown” it to Android 2.1 (API level 7) and + by making following
modifications:

1) Install
and add Support Librairies v4 and v7 to
your project ( http://developer.android.com/tools/support-library/setup.html )
2) Delete
android:minHeight=”?android:attr/listPreferredItemHeightSmall” and android:textAppearance=”?android:attr/textAppearanceListItemSmall”
lines from “drawer_list_item.xml”, you can style it in another way or
just keep it without theses lines.
3) You should extend ActionBarActivity instead of
FragmentActivity or Fragment
4) Change your App Theme
to @style/Theme.AppCompat or @style/Theme.AppCompat.Light etc…
5) Change calls to
getActionBar() for getSupportActionBar()
6) Change
calls to invalidateOptionsMenu() for supportInvalidateOptionsMenu()

Regards.

Latino_Review
Latino_Review
6 years ago
Reply to  Sami M.

Finally i made it works, thanks to your tips. But there’s something wrong in left list the selected item doesn’t change the color to red like in the image in tutorial. But it happens only on device a Xperia X10 2.3.3, but in the AVD with Android 4.2 it runs fine. Any idea on why it happens ?

Rhino
Rhino
6 years ago

Hi Ravi, thanks for the tutorials.
I have a question, how to do it if I would like to work it with WebView?
Thanks

1614
0
Would love your thoughts, please comment.x
()
x