2016-07-21 17:53 957人阅读 评论(0) 收藏 举报
 分类:
android(9) 

版权声明:本文为博主原创文章,未经博主允许不得转载。

本文地址:http://blog.csdn.net/u011181236/article/details/51985242

1.布局要注意的就是 
Android:layout_gravity=”right”

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

2.Java代码 
这个是设置toolbar里左上角menu按钮的点击事件

toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!drawer.isDrawerOpen(setDrawerGravity())) {
drawer.openDrawer(setDrawerGravity());
}
}
});

3.这里只有4个属性可用

Gravity.LEFT to move the left drawer or Gravity.RIGHT for the right.GravityCompat.START or GravityCompat.END may also be used.

private int setDrawerGravity() {
return Gravity.RIGHT;
}

4.返回键处理

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(setDrawerGravity())) {
drawer.closeDrawer(setDrawerGravity());
} else {
super.onBackPressed();
}
}

5.NavigationView 的item点击处理

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener(){
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(setDrawerGravity());
int id = item.getItemId(); if (id == R.id.nav_camera) {
// Handle the camera action
}
return true;
}
});

1

 

(转载) 使用DrawerLayout和NavigationView从右侧出现的更多相关文章

  1. Android CoordinatorLayout、AppBarLayout、DrawerLayout、NavigationView 的使用及问题小结

    这里只对Material Design中这几种组件使用的重要部分以及容易出现问题的地方进行汇总(遇坑请直接看最后常见问题部分),详细用法请自行查阅官方文档 一.CoordinatorLayout 介绍 ...

  2. DrawerLayout 和 NavigationView 的使用

    参考: 1.NavigationView 的使用 2.NavigationView更改菜单icon和title颜色变化效果 3.Android 自己实现 NavigationView 转了第一篇   ...

  3. <Android 基础(七)> DrawerLayout and NavigationView

    介绍 DrawerLayout是Support Library包中实现了侧滑菜单效果的控件 android.support.v4.widget.DrawerLayout NavigationView是 ...

  4. android29之UI控件的抽屉式实现方法之一(DrawerLayout和NavigationView)

    添加依赖 implementation 'com.google.android.material:material:1.2.0-alpha06' 在Layout中创建两个Xml布局文件,header. ...

  5. Android Material Design控件学习(二)——NavigationView的学习和使用

    前言 上次我们学习了TabLayout的用法,今天我们继续学习MaterialDesign(简称MD)控件--NavigationView. 正如其名,NavigationView,导航View.一般 ...

  6. android侧滑菜单笔记

    一.SlidingPaneLayout v4包下的控件,使用简单,功能简洁.官方文档明确说明该控件只能左侧滑动.使用如下: <android.support.v4.widget.SlidingP ...

  7. Android通知栏沉浸式/透明化完整解决方案

    转载请注明出处:http://www.cnblogs.com/cnwutianhao/p/6640649.html 参考文献:https://github.com/ljgsonx/adaptiveSt ...

  8. 屠龙之路_假期罢工和公主私奔_SixthDay

    摘要:屠龙少年经过一周的长途跋涉后,终于来到了传说中的周末客栈.周末客栈是屠龙之路的必经之地,屠龙少年可以在周末客栈补给干粮,修补装备,好好休息一下,以便更好的上路.周末客栈有个不成文的规定:凡入住者 ...

  9. NavigationDrawer和NavigationView-Android M新控件

    Translucent System Bars-4.4新特性 Toolbar-5.0新特性 NavigationDrawer 简介 NavigationDrawer 是 Google 在 Materi ...

随机推荐

  1. BZOJ 3105 线性基 高斯消元

    思路: 按照从大到小排个序 维护两个数组 一个是消元后的 另一个是 按照消元的位置排的 不断 维护从大到小 (呃具体见代码) //By SiriusRen #include <cstdio> ...

  2. marge into操作

    动机: 想在Oracle中用一条SQL语句直接进行Insert/Update的操作. 说明: 在进行SQL语句编写时,我们经常会遇到大量的同时进行Insert/Update的语句 ,也就是说当存在记录 ...

  3. Java基础——GridBagLayout布局

    1.GridBagLayout布局管理器非常灵活,每个 GridBagLayout 对象维持一个动态的矩形单元网格: 2.需要和它的约束类(GridBagConstraints类)一起使用: 3.Gr ...

  4. VSCode (Code) 技法

    本人使用插件推荐 indent-rainbow https://marketplace.visualstudio.com/items?itemName=oderwat.indent-rainbow B ...

  5. CSS实现栅格布局

    CSS实现栅格布局 设置容器container: .grid-container { width: 100%; max-width: 1200px; } 清除浮动: .row:before, .row ...

  6. ng-repeat 中的 track by $index

    用ng-repeat指令遍历一个javascript数组,当数组中有重复元素的时候,angularjs会报错,这是因为ng-Repeat不允许collection中存在两个相同Id的对象. 对于数字或 ...

  7. Qwiklab'实验-CloudFront, EFS, S3'

    title: AWS之Qwiklab subtitle: 3. Qwiklab'实验-CloudFront, EFS, S3' date: 2018-09-21 17:29:20 --- Introd ...

  8. Pyhton学习——Day7

    ##############################################匿名函数################################################## ...

  9. UVALive-7197 Axles 动态规划 多个背包问题

    题目链接:https://cn.vjudge.net/problem/UVALive-7197 题意 需要生产n种(2<=n<=14)零件,每种零件可以用两种材料制作,对这两种材料的消耗相 ...

  10. [Codeforces 226E]Noble Knight's Path

    题目大意:有一棵n个节点的树,m年.初始每个节点都有.每天有如下操作:1. 给定c,让c没有(c只可能没有一次).2. 给定s,t,k,y,求从第y+1年到现在(即忽略y+1年之前的操作1),s到t的 ...