参考链接:http://blog.csdn.net/u012702547/article/details/51253222

1.一般来讲,是配合drawerLayout使用的,在xml文件中声明,其中layout_gravity,是drawerlayout中的

<android.support.design.widget.NavigationView
android:id="@+id/home_activity_drawer_drawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/activity_home_drawer"> </android.support.design.widget.NavigationView>

2.在res中新建menu文件夹,在menu文件夹下,新建

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!--<group android:id="@+id/g1">-->
<item
android:id="@+id/home_activity_drawer_alarm"
android:icon="@drawable/alarm_icon"
android:title="@string/home_activity_drawer_alarm"/>
<!--</group>-->
<!--<group android:id="@+id/g2">-->
<item
android:id="@+id/home_activity_drawer_backlight"
android:icon="@drawable/backlight_setting_icon"
android:title="@string/home_activity_drawer_backlight"/>
<!--</group>-->
<!--<group android:id="@+id/g3">-->
<item
android:id="@+id/home_activity_drawer_about_us"
android:icon="@drawable/about_us_icon"
android:title="@string/home_activity_drawer_about_us"/>
<!--</group>-->
<!--<group android:id="@+id/g4">-->
<item
android:id="@+id/home_activity_drawer_device"
android:icon="@drawable/device_icon"
android:title="@string/home_activity_drawer_device"
/>
<!--</group>-->
<!--<group android:id="@+id/g5">-->
<item
android:id="@+id/home_activity_drawer_user_profile"
android:icon="@drawable/user_profile_icon"
android:title="@string/home_activity_drawer_user_profile"/>
<!--</group>--> </menu>

每一个item,用group包裹,并声明id,可添加分割线, group有一个

 android:checkableBehavior=""
//三种选择
//sigle 单选
//all 复选
//none 没有可复选性

这样做出的图标是灰色的,设置图标非灰色

NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
navigationView.setItemIconTintList(null);

1.app:itemBackground="@color/colorAccent"设置每一个item的背景颜色

2.app:itemTextColor=""设置item的背景颜色

头部点击事件,首先获得头部的View

 View headerView = navigationView.getHeaderView(0);  

然后,正常处理点击事件即可

item点击事件

navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
//在这里处理item的点击事件
return true;
}
});

negativeView 的使用的更多相关文章

随机推荐

  1. windows下的C++ socket服务器(4)

    void handleAccept(int socket_fd) { ] = { '\0' }; string cmd; string filename; recv(socket_fd, buf, ) ...

  2. 转 js事件探秘

    Javascript中的事件,可以和html交互. 事件流IE&Opera:事件冒泡其他浏览器: 事件捕获 事件冒泡:事件由最具体的元素(文档中嵌套层次最深的那个节点)接收,然后逐级向上传播至 ...

  3. Spring 2.0

    ProductBacklog:继续向下细化; 1.界面美化,统一界面风格,以简洁美观为主: 2.丰富版面的内容,吸引用户: 3.尝试增加新的版面: Sprint 计划会议:确定此次冲刺要完成的目标 1 ...

  4. HDU 2103 Family planning

    http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,there are so m ...

  5. 利用stream对map集合进行过滤

    最近公司在大张旗鼓的进行代码审核,从中也发现自己写代码的不好习惯.一次无意的点到了公司封装的对map集合过滤的方法,发现了stream.于是研究了一下.并对原有的代码再次结合Optional进行重构下 ...

  6. onMeasure实例分析

    本文转自:http://blog.csdn.net/u012604322/article/details/17097105           上面这个两个视图是Android API中没有给出来的但 ...

  7. JDBC数据库连接技术

    [学习笔记]JDBC数据库连接技术(Java Database Connectivity) 一.JDBC简介 Java是通过JDBC技术实现对各种数据库的访问的,JDBC是Java数据库连接技术的简称 ...

  8. PGM学习之五 贝叶斯网络

    本文的主题是“贝叶斯网络”(Bayesian Network) 贝叶斯网络是一个典型的图模型,它对感兴趣变量(variables of interest)及变量之间的关系(relationships) ...

  9. matplotlib + pandas绘图

    利用pandas处理日期数据,并根据日期绘制增长率曲线. 处理的json文本内容如下: # pd.json [{"name": "A", "date& ...

  10. 【BZOJ2733】永无乡(线段树,并查集)

    [BZOJ2733]永无乡(线段树,并查集) 题面 BZOJ 题解 线段树合并 线段树合并是一个很有趣的姿势 前置技能:动态开点线段树 具体实现:每次合并两棵线段树的时候,假设叫做\(t1,t2\), ...