Android NavigationView显示在NavigationBar下,无法单击

Android NavigationView显示在NavigationBar下,无法单击,android,material-design,navigationbar,navigationview,Android,Material Design,Navigationbar,Navigationview,如您所见,NavigationView的背景已设置为android:cliptoppadding='false',可以在透明的NavigationBar下看到 但是NavigationView(NavigationDrawer)无法完全向上滚动到NavigationBar上方,如何解决这个问题 我希望列表项滚动到导航栏的顶部,这意味着最后一次发送不是在导航栏下方,而是在上方 layout/activity\u main.xml <?xml version="1.0" encoding

如您所见,
NavigationView
的背景已设置为
android:cliptoppadding='false'
,可以在透明的
NavigationBar
下看到

但是
NavigationView(NavigationDrawer)
无法完全向上滚动到
NavigationBar
上方,如何解决这个问题

我希望列表项滚动到
导航栏
的顶部,这意味着最后一次
发送
不是在
导航栏
下方,而是在
上方


layout/activity\u main.xml

<?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"
        android:clipToPadding="false"
        android:clipChildren="false"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer">
    </android.support.design.widget.NavigationView>

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


嗯,代码是这样运行的,我无法搜索有用的答案


欢迎任何意见,谢谢

您可以在导航中使用RecyclerView

在导航适配器中:

public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.ViewHolder>
NavMenuItem.java

package your package name.Model;

import your package name.Enum.NavItemType;

/**
 * Created by mehrdad on 11/16/2015.
 */
public class NavMenuItem
{
    private NavItemType itemType;
    private int resourceId;

    public NavItemType getItemType()
    {
        return itemType;
    }

    public void setItemType(NavItemType itemType)
    {
        this.itemType = itemType;
    }

    public int getResourceId()
    {
        return resourceId;
    }

    public void setResourceId(int resourceId)
    {
        this.resourceId = resourceId;
    }
}
NavMenuParser.java

package your package name.Util;

import android.support.v7.view.menu.MenuBuilder;
import android.view.MenuItem;

import your package name.Enum.NavItemType;
import your package name.Model.NavMenuItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mehrdad on 11/16/2015.
 */
public class NavMenuParser
{
    public static List<NavMenuItem> parse(MenuBuilder menu){
        List<NavMenuItem> navMenuItems = new ArrayList<>();
        int groupId = menu.getItem(0).getGroupId();
        for (MenuItem menuItem : menu.getVisibleItems())
        {
            if(menuItem.getGroupId() != groupId)
            {
                groupId = menuItem.getGroupId();
                NavMenuItem navGroup = new NavMenuItem();
                navGroup.setItemType(NavItemType.Group);
                navGroup.setResourceId(groupId);
                navMenuItems.add(navGroup);
            }
            NavMenuItem navItem = new NavMenuItem();
            navItem.setItemType(NavItemType.Item);
            navItem.setResourceId(menuItem.getItemId());
            navMenuItems.add(navItem);
        }
        return navMenuItems;
    }
}
NavigationDrawerRadapter.java

package your package name.Adapter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import your package name.Activity.LoginActivity;
import your package name.Activity.RegisterActivity;
import your package name.Enum.NavItemType;
import your package name.Model.NavMenuItem;
import your package name.Network.VolleySingleton;
import your package name.R;
import your package name.Util.AppConstant;
import your package name.Util.NavMenuParser;

import java.util.List;


public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.ViewHolder>
{

    private static final int TYPE_HEADER = 0;  // Declaring Variable to Understand which View is being worked on
    // IF the view under inflation and population is navigation_drawer_header or Item
    private static final int TYPE_ITEM = 1;
    private static final int TYPE_SEPARATOR = 2;
    private String username;        //String Resource for navigation_drawer_header View txtUsername
    private List<NavMenuItem> navMenuItems;
    private Menu menu;
    private String userPictureUrl;        //int Resource for navigation_drawer_header view userPictureUrl picture
    private String email;       //String Resource for navigation_drawer_header view txtEmail
    private ImageLoader imageLoader;
    // Creating a ViewHolder which extends the RecyclerView View Holder
    // ViewHolder are used to to store the inflated views in order to recycle them

    public NavigationDrawerAdapter(final Context context,MenuBuilder menu, final String username, String email, String userPictureUrl)
    { // NavigationDrawerAdapter Constructor with titles and icons parameter
        navMenuItems = NavMenuParser.parse(menu);
        VolleySingleton volleySingleton = VolleySingleton.getInstance(context);
        imageLoader = volleySingleton.getImageLoader();
        this.menu = menu;
        this.username = username;
        this.email = email;
        this.userPictureUrl = userPictureUrl;                     //here we assign those passed values to the values we declared here in adapter
        ViewHolder.setViewHolderClickListener(new ViewHolder.ViewHolderClickListener()
        {
            @Override
            public void onNavigationItemClick(int position)
            {

            }

            @Override
            public void onNavigationHeaderClick()
            {
                Toast.makeText(context, "Go to imgProfilePicture info!", Toast.LENGTH_LONG).show();

                new AlertDialog.Builder(context).setIcon(android.R.drawable.ic_dialog_info).setTitle("welcome")
                        .setMessage("...")
                        .setPositiveButton("login", new DialogInterface.OnClickListener()
                        {
                            @Override
                            public void onClick(DialogInterface dialog, int which)
                            {
                                Intent intent = new Intent(context,LoginActivity.class);
                                context.startActivity(intent);
//                                startActivity(intent);
                            }
                        }).setNegativeButton("register", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        Intent intent = new Intent(context, RegisterActivity.class);
                        context.startActivity(intent);
//                        startActivity(intent);
                    }
                }).show();

//                Intent i = new Intent(context, UserDetailActivity.class);
//                Bundle bundle = new Bundle();
//                bundle.putString("username", username);
//                i.putExtras(bundle);
//                context.startActivity(i);
            }
        });
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        View v = null;
        switch (viewType)
        {
            case TYPE_HEADER:
                v = LayoutInflater.from(parent.getContext()).inflate(R.layout.navigation_drawer_header, parent, false); //Inflating the layout
                break;
            case TYPE_ITEM:
                v = LayoutInflater.from(parent.getContext()).inflate(R.layout.navigation_drawer_item, parent, false); //Inflating the layout
                break;
            case TYPE_SEPARATOR:
                v = LayoutInflater.from(parent.getContext()).inflate(R.layout.navigation_drawer_separator, parent, false); //Inflating the layout
                break;
        }
        return new ViewHolder(v, viewType); // Returning the created object

    }


    //Below first we override the method onCreateViewHolder which is called when the ViewHolder is
    //Created, In this method we inflate the navigation_drawer_item layout if the viewType is Type_ITEM or else we inflate navigation_drawer_header.xml_drawer_header.xml
    // if the viewType is TYPE_HEADER
    // and pass it to the view holder

    //Next we override a method which is called when the item in a row is needed to be displayed, here the int position
    // Tells us item at which position is being constructed to be displayed and the holder id of the holder object tell us
    // which view type is being created 1 for item row
    @Override
    public void onBindViewHolder(ViewHolder holder, int position)
    {
        switch (holder.viewType)
        {
            case TYPE_ITEM:
                // as the list view is going to be called after the navigation_drawer_header view so we decrement the
                // position by 1 and pass it to the holder while setting the text and image
                MenuItem menuItem = menu.findItem(navMenuItems.get(position - 1).getResourceId());
                holder.txtNavItemText.setText(menuItem.getTitle()); // Setting the Text with the array of our Titles
                holder.imgNavItemIcon.setImageDrawable(menuItem.getIcon());// Setting the image with array of our icons
                break;
            case TYPE_HEADER:
                if(userPictureUrl != null)
                {
                    String pictureUrl = AppConstant.URL_ROOT + userPictureUrl;
                    holder.imgProfilePicture.setImageUrl(pictureUrl,imageLoader);           // Similarly we set the resources for navigation_drawer_header view
                }
                holder.txtUsername.setText(username);
                holder.txtEmail.setText(email);
                break;
        }
    }

    // This method returns the number of items present in the list
    @Override
    public int getItemCount()
    {
        return navMenuItems.size() + 1; // the number of items in the list will be +1 the titles including the navigation_drawer_header view.
    }

    // With the following method we check what type of view is being passed
    @Override
    public int getItemViewType(int position)
    {
        if (position == 0)
            return TYPE_HEADER;
        if (navMenuItems.get(position - 1).getItemType() == NavItemType.Group)
            return TYPE_SEPARATOR;

        return TYPE_ITEM;
    }


    public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
    {
        private int viewType;

        private TextView txtNavItemText;
        private ImageView imgNavItemIcon;
        private NetworkImageView imgProfilePicture;
        private TextView txtUsername;
        private TextView txtEmail;
        private static ViewHolderClickListener viewHolderClickListener;

        public ViewHolder(View itemView, int viewType)
        {
            // Creating ViewHolder Constructor with View and viewType As a parameter
            super(itemView);
            this.viewType = viewType;

            if (viewType != TYPE_SEPARATOR)
            {
                itemView.setClickable(true);
                itemView.setOnClickListener(this);
                // Here we set the appropriate view in accordance with the the view type as passed when the holder object is created
                switch (viewType)
                {
                    case TYPE_ITEM:
                        txtNavItemText = (TextView) itemView.findViewById(R.id.rowText); // Creating TextView object with the id of txtNavItemText from navigation_drawer_item_rowon_drawer_item_row.xml
                        imgNavItemIcon = (ImageView) itemView.findViewById(R.id.rowIcon);// Creating ImageView object with the id of ImageView from navigation_drawer_item_rowon_drawer_item_row.xml                 // setting holder id as 1 as the object being populated are of type item row
                        break;
                    case TYPE_HEADER:
                        txtUsername = (TextView) itemView.findViewById(R.id.name);         // Creating Text View object from navigation_drawer_headertion_drawer_header.xml for name
                        txtEmail = (TextView) itemView.findViewById(R.id.txt_edit_email);       // Creating Text View object from navigation_drawer_header.xml_drawer_header.xml for txtEmail
                        imgProfilePicture = (NetworkImageView) itemView.findViewById(R.id.circleView);// Creating Image view object from navigation_drawer_headertion_drawer_header.xml for userPictureUrl pic                 // Setting holder id = 0 as the object being populated are of type navigation_drawer_header view
                        break;
                }
            }

        }

        public static void setViewHolderClickListener(ViewHolderClickListener viewHolderClickListener)
        {
            ViewHolder.viewHolderClickListener = viewHolderClickListener;
        }

        public interface ViewHolderClickListener
        {
            void onNavigationItemClick(int position);

            void onNavigationHeaderClick();
        }

        @Override
        public void onClick(View v)
        {
            switch (viewType)
            {
                case TYPE_HEADER:
                    viewHolderClickListener.onNavigationHeaderClick();
                    break;

                case TYPE_ITEM:
                    viewHolderClickListener.onNavigationItemClick(getAdapterPosition());
                    break;
            }
        }
    }
}

多亏了
mehrdad khosravi
!他的解决方案确实是一个很好的方向,而且更具艺术性

但我太懒了,所以我有另一个但不是那种艺术性的解决方案:从
导航视图
扩展

package your.package;

import android.content.Context;
import android.support.design.widget.NavigationView;
import android.util.AttributeSet;

import another.package.ScreenTool;

/**
 * This view makes the NavigationDrawer fit system view.
 * Created by MewX on 1/19/2016.
 */
public class NavigationFitSystemView extends NavigationView {
    public NavigationFitSystemView(Context context) {
        super(context);
    }

    public NavigationFitSystemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NavigationFitSystemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthSpec, int heightSpec) {

        // TODO: optimize for tablet screen layout
        super.onMeasure(widthSpec, heightSpec- ScreenTool.getCurrentNavigationBarSize(getContext()).y);
    }
}

还有,
ScreenTool.java

package another.package;

import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.view.Display;
import android.view.WindowManager;

/**
 * This class contains many screen-relate functions.
 * Created by MewX on 1/18/2016.
 */
@SuppressWarnings("unused")
public class ScreenTool {
    /**
     * get status bar height in px, this is the defined value whenever statusBar is displayed.
     * @param context current context
     * @return px int status bar height
     */
    public static int getStatusBarHeightValue(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result; // in px
    }

    /**
     * get navigation bar height in px, this is the defined value whenever navBar is displayed.
     * @param context current context
     * @return px int navigation bar height
     */
    public static int getNavigationBarHeightValue(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result; // in px
    }

    /**
     * get current navigation bar size:
     *   if bar not displaying, the values is zero;
     *   else is the width and height value;
     * @param context current context
     * @return new Point(width, height)
     */
    public static Point getCurrentNavigationBarSize(Context context) {
        Point appUsableSize = getAppUsableScreenSize(context);
        Point realScreenSize = getRealScreenSize(context);

        // navigation bar on the right
        if (appUsableSize.x < realScreenSize.x) {
            return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
        }

        // navigation bar at the bottom
        if (appUsableSize.y < realScreenSize.y) {
            return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
        }

        // navigation bar is not present
        return new Point();
    }

    /**
     * get application usable screen size.
     * @param context current size
     * @return new Point(width, height)
     */
    public static Point getAppUsableScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size;
    }

    /**
     * get actual/real screen size, this is the full screen size.
     * @param context current context
     * @return new Point(width, height)
     */
    public static Point getRealScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point size = new Point();

        if (Build.VERSION.SDK_INT >= 17) {
            display.getRealSize(size);
        } else if (Build.VERSION.SDK_INT >= 14) {
            try {
                size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
                size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
            } catch (Exception e) {
                size = new Point(0, 0);
            }
        }
        return size;
    }
}
package-other.package;
导入android.content.Context;
导入android.graphics.Point;
导入android.os.Build;
导入android.view.Display;
导入android.view.WindowManager;
/**
*此类包含许多与屏幕相关的函数。
*MewX于2016年1月18日创建。
*/
@抑制警告(“未使用”)
公共类屏幕工具{
/**
*以px为单位获取状态栏高度,这是显示状态栏时定义的值。
*@param context当前上下文
*@return px int状态栏高度
*/
公共静态int getStatusBarHeightValue(上下文){
int结果=0;
int resourceId=context.getResources().getIdentifier(“status\u bar\u height”、“dimen”、“android”);
如果(资源ID>0){
结果=context.getResources().getDimensionPixelSize(resourceId);
}
返回结果;//在px中
}
/**
*以px为单位获取导航栏高度,这是显示导航栏时定义的值。
*@param context当前上下文
*@return px int导航条高度
*/
公共静态int getNavigationBarHeightValue(上下文){
int结果=0;
int resourceId=context.getResources().getIdentifier(“导航栏高度”、“尺寸”、“安卓”);
如果(资源ID>0){
结果=context.getResources().getDimensionPixelSize(resourceId);
}
返回结果;//在px中
}
/**
*获取当前导航栏大小:
*如果条形图未显示,则值为零;
*else是宽度和高度值;
*@param context当前上下文
*@返回新点(宽度、高度)
*/
公共静态点getCurrentNavigationBarSize(上下文){
Point appUsableSize=getAppUsableScreenSize(上下文);
Point realScreenSize=getRealScreenSize(上下文);
//右边的导航栏
if(appUsableSize.x=17){
display.getRealSize(大小);
}else if(Build.VERSION.SDK_INT>=14){
试一试{
size.x=(整数)Display.class.getMethod(“getRawWidth”).invoke(Display);
size.y=(整数)Display.class.getMethod(“getRawHeight”).invoke(Display);
}捕获(例外e){
大小=新点(0,0);
}
}
返回大小;
}
}

然后,将布局文件从

删除更改

name="android:windowTranslucentNavigation">true

style.xml中的主题看一看“”@onurtaskin谢谢,根据代码计算确实是一个可行的解决方案,但是当用户隐藏/显示
导航栏时会出现问题。它不能随
NavigationBar
的隐藏/显示一起更改,因为我没有找到捕获
NavigationBar
事件(t.t)的解决方案,所以我更愿意获得一个更改
xml
文件的解决方案:)上面由
onur taskin
创建的链接与我的问题不同,所以不能使用。您的意思是使用
RecyclerView
保存
NavigationView
中的所有项目?我想知道我可能需要处理所有项目的颜色一个接一个,就像?(因为每次点击后,项目都会改变颜色。)不管怎样,请在你高兴的时候写更多的细节,谢谢~是的。它的工作很好,而且吃饱了,但这是一条艰难的道路。为此,我编写了6个xml类和3个java类。当我不忙的时候,我会给你我的密码。你还需要那个答案吗?我没有更多的时间了
package your package name.Enum;

/**
 * Created by mehrdad on 11/16/2015.
 */
public enum NavItemType
{
    Item,
    Group
}
package your package name.Model;

import your package name.Enum.NavItemType;

/**
 * Created by mehrdad on 11/16/2015.
 */
public class NavMenuItem
{
    private NavItemType itemType;
    private int resourceId;

    public NavItemType getItemType()
    {
        return itemType;
    }

    public void setItemType(NavItemType itemType)
    {
        this.itemType = itemType;
    }

    public int getResourceId()
    {
        return resourceId;
    }

    public void setResourceId(int resourceId)
    {
        this.resourceId = resourceId;
    }
}
package your package name.Util;

import android.support.v7.view.menu.MenuBuilder;
import android.view.MenuItem;

import your package name.Enum.NavItemType;
import your package name.Model.NavMenuItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mehrdad on 11/16/2015.
 */
public class NavMenuParser
{
    public static List<NavMenuItem> parse(MenuBuilder menu){
        List<NavMenuItem> navMenuItems = new ArrayList<>();
        int groupId = menu.getItem(0).getGroupId();
        for (MenuItem menuItem : menu.getVisibleItems())
        {
            if(menuItem.getGroupId() != groupId)
            {
                groupId = menuItem.getGroupId();
                NavMenuItem navGroup = new NavMenuItem();
                navGroup.setItemType(NavItemType.Group);
                navGroup.setResourceId(groupId);
                navMenuItems.add(navGroup);
            }
            NavMenuItem navItem = new NavMenuItem();
            navItem.setItemType(NavItemType.Item);
            navItem.setResourceId(menuItem.getItemId());
            navMenuItems.add(navItem);
        }
        return navMenuItems;
    }
}
package com.khosravi.mehrdadz.garagesale.Fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

import your package name.Adapter.NavigationDrawerAdapter;
import your package name.R;
import your package name.Util.SessionManager;

import de.hdodenhof.circleimageview.CircleImageView;


public class NavigationDrawerFragment extends Fragment
{

    RecyclerView mRecyclerView;                           // Declaring RecyclerView
    NavigationDrawerAdapter mAdapter;                        // Declaring Adapter For Recycler View
    RecyclerView.LayoutManager mLayoutManager;            // Declaring Layout Manager as a linear layout manager
    private SessionManager session;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View fragmentView = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);

        session = new SessionManager(getActivity());

        String userName = session.getUsername();
        String email = session.getEmail();
        String pictureUrl = session.getPictureUrl();

        mRecyclerView = (RecyclerView) fragmentView.findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

        mRecyclerView.setHasFixedSize(true);                            // Letting the system know that the list objects are of fixed size
        MenuBuilder menu = new MenuBuilder(getActivity());
        new MenuInflater(getActivity()).inflate(R.menu.navigation_drawer_menu, menu);
        mAdapter = new NavigationDrawerAdapter(getActivity(),menu, userName, email, pictureUrl );       // Creating the Adapter of NavigationDrawerAdapter class(which we are going to see in a bit)
        // And passing the titles,icons,navigation_drawer_header view name, navigation_drawer_header view email,
        // and navigation_drawer_header view profile picture

        mRecyclerView.setAdapter(mAdapter);                              // Setting the adapter to RecyclerView

        mLayoutManager = new LinearLayoutManager(getActivity());                 // Creating a layout Manager

        mRecyclerView.setLayoutManager(mLayoutManager);                 // Setting the layout Manager

        return fragmentView;
    }
}
package your package name.Adapter;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.view.menu.MenuBuilder;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import your package name.Activity.LoginActivity;
import your package name.Activity.RegisterActivity;
import your package name.Enum.NavItemType;
import your package name.Model.NavMenuItem;
import your package name.Network.VolleySingleton;
import your package name.R;
import your package name.Util.AppConstant;
import your package name.Util.NavMenuParser;

import java.util.List;


public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.ViewHolder>
{

    private static final int TYPE_HEADER = 0;  // Declaring Variable to Understand which View is being worked on
    // IF the view under inflation and population is navigation_drawer_header or Item
    private static final int TYPE_ITEM = 1;
    private static final int TYPE_SEPARATOR = 2;
    private String username;        //String Resource for navigation_drawer_header View txtUsername
    private List<NavMenuItem> navMenuItems;
    private Menu menu;
    private String userPictureUrl;        //int Resource for navigation_drawer_header view userPictureUrl picture
    private String email;       //String Resource for navigation_drawer_header view txtEmail
    private ImageLoader imageLoader;
    // Creating a ViewHolder which extends the RecyclerView View Holder
    // ViewHolder are used to to store the inflated views in order to recycle them

    public NavigationDrawerAdapter(final Context context,MenuBuilder menu, final String username, String email, String userPictureUrl)
    { // NavigationDrawerAdapter Constructor with titles and icons parameter
        navMenuItems = NavMenuParser.parse(menu);
        VolleySingleton volleySingleton = VolleySingleton.getInstance(context);
        imageLoader = volleySingleton.getImageLoader();
        this.menu = menu;
        this.username = username;
        this.email = email;
        this.userPictureUrl = userPictureUrl;                     //here we assign those passed values to the values we declared here in adapter
        ViewHolder.setViewHolderClickListener(new ViewHolder.ViewHolderClickListener()
        {
            @Override
            public void onNavigationItemClick(int position)
            {

            }

            @Override
            public void onNavigationHeaderClick()
            {
                Toast.makeText(context, "Go to imgProfilePicture info!", Toast.LENGTH_LONG).show();

                new AlertDialog.Builder(context).setIcon(android.R.drawable.ic_dialog_info).setTitle("welcome")
                        .setMessage("...")
                        .setPositiveButton("login", new DialogInterface.OnClickListener()
                        {
                            @Override
                            public void onClick(DialogInterface dialog, int which)
                            {
                                Intent intent = new Intent(context,LoginActivity.class);
                                context.startActivity(intent);
//                                startActivity(intent);
                            }
                        }).setNegativeButton("register", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialog, int which)
                    {
                        Intent intent = new Intent(context, RegisterActivity.class);
                        context.startActivity(intent);
//                        startActivity(intent);
                    }
                }).show();

//                Intent i = new Intent(context, UserDetailActivity.class);
//                Bundle bundle = new Bundle();
//                bundle.putString("username", username);
//                i.putExtras(bundle);
//                context.startActivity(i);
            }
        });
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
        View v = null;
        switch (viewType)
        {
            case TYPE_HEADER:
                v = LayoutInflater.from(parent.getContext()).inflate(R.layout.navigation_drawer_header, parent, false); //Inflating the layout
                break;
            case TYPE_ITEM:
                v = LayoutInflater.from(parent.getContext()).inflate(R.layout.navigation_drawer_item, parent, false); //Inflating the layout
                break;
            case TYPE_SEPARATOR:
                v = LayoutInflater.from(parent.getContext()).inflate(R.layout.navigation_drawer_separator, parent, false); //Inflating the layout
                break;
        }
        return new ViewHolder(v, viewType); // Returning the created object

    }


    //Below first we override the method onCreateViewHolder which is called when the ViewHolder is
    //Created, In this method we inflate the navigation_drawer_item layout if the viewType is Type_ITEM or else we inflate navigation_drawer_header.xml_drawer_header.xml
    // if the viewType is TYPE_HEADER
    // and pass it to the view holder

    //Next we override a method which is called when the item in a row is needed to be displayed, here the int position
    // Tells us item at which position is being constructed to be displayed and the holder id of the holder object tell us
    // which view type is being created 1 for item row
    @Override
    public void onBindViewHolder(ViewHolder holder, int position)
    {
        switch (holder.viewType)
        {
            case TYPE_ITEM:
                // as the list view is going to be called after the navigation_drawer_header view so we decrement the
                // position by 1 and pass it to the holder while setting the text and image
                MenuItem menuItem = menu.findItem(navMenuItems.get(position - 1).getResourceId());
                holder.txtNavItemText.setText(menuItem.getTitle()); // Setting the Text with the array of our Titles
                holder.imgNavItemIcon.setImageDrawable(menuItem.getIcon());// Setting the image with array of our icons
                break;
            case TYPE_HEADER:
                if(userPictureUrl != null)
                {
                    String pictureUrl = AppConstant.URL_ROOT + userPictureUrl;
                    holder.imgProfilePicture.setImageUrl(pictureUrl,imageLoader);           // Similarly we set the resources for navigation_drawer_header view
                }
                holder.txtUsername.setText(username);
                holder.txtEmail.setText(email);
                break;
        }
    }

    // This method returns the number of items present in the list
    @Override
    public int getItemCount()
    {
        return navMenuItems.size() + 1; // the number of items in the list will be +1 the titles including the navigation_drawer_header view.
    }

    // With the following method we check what type of view is being passed
    @Override
    public int getItemViewType(int position)
    {
        if (position == 0)
            return TYPE_HEADER;
        if (navMenuItems.get(position - 1).getItemType() == NavItemType.Group)
            return TYPE_SEPARATOR;

        return TYPE_ITEM;
    }


    public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
    {
        private int viewType;

        private TextView txtNavItemText;
        private ImageView imgNavItemIcon;
        private NetworkImageView imgProfilePicture;
        private TextView txtUsername;
        private TextView txtEmail;
        private static ViewHolderClickListener viewHolderClickListener;

        public ViewHolder(View itemView, int viewType)
        {
            // Creating ViewHolder Constructor with View and viewType As a parameter
            super(itemView);
            this.viewType = viewType;

            if (viewType != TYPE_SEPARATOR)
            {
                itemView.setClickable(true);
                itemView.setOnClickListener(this);
                // Here we set the appropriate view in accordance with the the view type as passed when the holder object is created
                switch (viewType)
                {
                    case TYPE_ITEM:
                        txtNavItemText = (TextView) itemView.findViewById(R.id.rowText); // Creating TextView object with the id of txtNavItemText from navigation_drawer_item_rowon_drawer_item_row.xml
                        imgNavItemIcon = (ImageView) itemView.findViewById(R.id.rowIcon);// Creating ImageView object with the id of ImageView from navigation_drawer_item_rowon_drawer_item_row.xml                 // setting holder id as 1 as the object being populated are of type item row
                        break;
                    case TYPE_HEADER:
                        txtUsername = (TextView) itemView.findViewById(R.id.name);         // Creating Text View object from navigation_drawer_headertion_drawer_header.xml for name
                        txtEmail = (TextView) itemView.findViewById(R.id.txt_edit_email);       // Creating Text View object from navigation_drawer_header.xml_drawer_header.xml for txtEmail
                        imgProfilePicture = (NetworkImageView) itemView.findViewById(R.id.circleView);// Creating Image view object from navigation_drawer_headertion_drawer_header.xml for userPictureUrl pic                 // Setting holder id = 0 as the object being populated are of type navigation_drawer_header view
                        break;
                }
            }

        }

        public static void setViewHolderClickListener(ViewHolderClickListener viewHolderClickListener)
        {
            ViewHolder.viewHolderClickListener = viewHolderClickListener;
        }

        public interface ViewHolderClickListener
        {
            void onNavigationItemClick(int position);

            void onNavigationHeaderClick();
        }

        @Override
        public void onClick(View v)
        {
            switch (viewType)
            {
                case TYPE_HEADER:
                    viewHolderClickListener.onNavigationHeaderClick();
                    break;

                case TYPE_ITEM:
                    viewHolderClickListener.onNavigationItemClick(getAdapterPosition());
                    break;
            }
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activity.HomeActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include layout="@layout/partial_toolbar"/>


    home activity budy 


    </LinearLayout>

    <include layout="@layout/partial_navigation_drawer"/>

</android.support.v4.widget.DrawerLayout>
DrawerLayout drawerLayout;
drawerLayout =(DrawerLayout) findViewById(R.id.drawer);

@Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
            case R.id.toggle_drawer:
                drawerLayout.openDrawer(GravityCompat.START);
            break;
        }
        return true;
    }
package your.package;

import android.content.Context;
import android.support.design.widget.NavigationView;
import android.util.AttributeSet;

import another.package.ScreenTool;

/**
 * This view makes the NavigationDrawer fit system view.
 * Created by MewX on 1/19/2016.
 */
public class NavigationFitSystemView extends NavigationView {
    public NavigationFitSystemView(Context context) {
        super(context);
    }

    public NavigationFitSystemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NavigationFitSystemView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthSpec, int heightSpec) {

        // TODO: optimize for tablet screen layout
        super.onMeasure(widthSpec, heightSpec- ScreenTool.getCurrentNavigationBarSize(getContext()).y);
    }
}
package another.package;

import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.view.Display;
import android.view.WindowManager;

/**
 * This class contains many screen-relate functions.
 * Created by MewX on 1/18/2016.
 */
@SuppressWarnings("unused")
public class ScreenTool {
    /**
     * get status bar height in px, this is the defined value whenever statusBar is displayed.
     * @param context current context
     * @return px int status bar height
     */
    public static int getStatusBarHeightValue(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result; // in px
    }

    /**
     * get navigation bar height in px, this is the defined value whenever navBar is displayed.
     * @param context current context
     * @return px int navigation bar height
     */
    public static int getNavigationBarHeightValue(Context context) {
        int result = 0;
        int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context.getResources().getDimensionPixelSize(resourceId);
        }
        return result; // in px
    }

    /**
     * get current navigation bar size:
     *   if bar not displaying, the values is zero;
     *   else is the width and height value;
     * @param context current context
     * @return new Point(width, height)
     */
    public static Point getCurrentNavigationBarSize(Context context) {
        Point appUsableSize = getAppUsableScreenSize(context);
        Point realScreenSize = getRealScreenSize(context);

        // navigation bar on the right
        if (appUsableSize.x < realScreenSize.x) {
            return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
        }

        // navigation bar at the bottom
        if (appUsableSize.y < realScreenSize.y) {
            return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
        }

        // navigation bar is not present
        return new Point();
    }

    /**
     * get application usable screen size.
     * @param context current size
     * @return new Point(width, height)
     */
    public static Point getAppUsableScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        return size;
    }

    /**
     * get actual/real screen size, this is the full screen size.
     * @param context current context
     * @return new Point(width, height)
     */
    public static Point getRealScreenSize(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();
        Point size = new Point();

        if (Build.VERSION.SDK_INT >= 17) {
            display.getRealSize(size);
        } else if (Build.VERSION.SDK_INT >= 14) {
            try {
                size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
                size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
            } catch (Exception e) {
                size = new Point(0, 0);
            }
        }
        return size;
    }
}
name="android:windowTranslucentNavigation">true