Android Material风格的应用(三)--DrawerLayout
添加抽屉导航
Android Material风格的应用(一)--AppBar TabLayout
Android Material风格的应用(二)--RecyclerView
Android Material风格的应用(三)--DrawerLayout
Android Material风格的应用(四)--FloatActionButton
Android Material风格的应用(五)--CollapsingToolbar
创建导航菜单
res/menu/menu-natigation.xml<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:icon="@drawable/ic_home_black_24dp"
android:tint="@color/button_grey"
android:title="One" />
<item android:icon="@drawable/ic_favorite_black_24dp"
android:tint="@color/button_grey"
android:title="Two"/>
<item android:icon="@drawable/ic_bookmark_border_black_24dp"
android:tint="@color/button_grey"
android:title="Three"/>
</group>
</menu>创建导航的布局
res/layout/navigation.xml<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="@dimen/navheader_height"
android:background="?attr/colorPrimaryDark"
android:padding="@dimen/md_keylines">
</LinearLayout>在
activity_main.xml中加入DrawerLayout,是DrawerLayout作为对顶层,使CoordinatorLayout作为它的
子级<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
......
</android.support.v4.widget.DrawerLayout>和
CoordinatorLayout的同一级添加NavigationView<android.support.design.widget.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/nav_view"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header"
app:menu="@menu/menu_navigation">在
MainActivity.javaonCreate中添加相关的逻辑NavigationView navigationView = (NavigationView)findViewById(R.id.nav_view);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer);
ActionBar supportActionBar = getSupportActionBar();
if(supportActionBar != null){
supportActionBar.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
supportActionBar.setDisplayHomeAsUpEnabled(true);
}
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
item.setChecked(true);
mDrawerLayout.closeDrawers();;
return true;
}
});相应左上角的menu,打开导航
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == android.R.id.home){
mDrawerLayout.openDrawer(GravityCompat.START);
}
return super.onOptionsItemSelected(item);
}
Android Material风格的应用(三)--DrawerLayout的更多相关文章
- Android Material风格的应用(五)--CollapsingToolbar
Collapsing Toolbar Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--RecyclerViewA ...
- Android Material风格的应用(四)--FloatActionButton
添加 FloatActionButton和SnackBar Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--Re ...
- Android Material风格的应用(二)--RecyclerView
添加RecyclerView Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--RecyclerViewAndro ...
- Android Material风格的应用(一)--AppBar TabLayout
打造Material风格的Android应用 Android Material风格的应用(一)--AppBar TabLayoutAndroid Material风格的应用(二)--RecyclerV ...
- Android Metro风格的Launcher开发系列第三篇
前言: 各位小伙伴,又到了每周更新文章了时候了,本来是周日能发出来呢,这不是赶上清明节吗,女王大人发话了,清明节前两天半陪她玩,只留给我周一下午半天时间写博客,哪里有女王哪里就有压迫呀有木有!好了闲话 ...
- Android Material Design控件学习(三)——使用TextInputLayout实现酷市场登录效果
前言 前两次,我们学习了 Android Material Design控件学习(一)--TabLayout的用法 Android Material Design控件学习(二)--Navigation ...
- Android Material Design之Toolbar与Palette
转:http://blog.csdn.net/jdsjlzx/article/details/41441083 前言 我们都知道Marterial Design是Google推出的全新UI设计规范,如 ...
- android Material Design详解
原文地址:http://blog.csdn.net/jdsjlzx/article/details/41441083/ 前言 我们都知道Marterial Design是Google推出的全新UI设计 ...
- Android Material Design 兼容库的使用
Android Material Design 兼容库的使用 mecury 前言:近来学习了Android Material Design 兼容库,为了把这个弄懂,才有了这篇博客,这里先推荐两篇博客: ...
随机推荐
- 【Eclipse中使用Git之一】把远程仓库的项目,clone到eclipse里面
[Eclipse中使用Git之一]把远程仓库的项目,clone到eclipse里面 2015-01-29 19:25 15779人阅读 评论(1) 收藏 举报 .embody{ padding:10p ...
- spring 使用c3po连接池
1 数据源:能够简单理解为数据的来源. 2 连接池:是缓存一定数量的数据库连接,当程序须要数据库连接的时候,直接在连接池中获取空暇的连接,使用完再放回连接池中,此连接又变成空暇状态,等待下一次连接. ...
- [Java开发之路](9)对象序列化与反序列化
1. 对象序列化 当你创建对象时.仅仅要你须要.它会一直存在,可是程序终止时,不管何时它都不会继续存在.虽然这样做是很有意义的,可是在某些情况下.假设程序不执行时扔能存在而且保存其信息,那将对我们很实 ...
- Log4j2 与 SpringMVC 整合
log4j2不仅仅是log4j的简单升级,而是整个项目的重构.官网地址:http://logging.apache.org/log4j/2.x/,大家能够从官网的介绍看出它相比log4j第1代的种种长 ...
- cache -- clear( 缓存清除的方法)
一:meta方法 <META HTTP-EQUIV="pragma" CONTENT="no-cache"> <META HTTP-EQUIV ...
- MATLAB 最优化计算 (二)
matlab 程序设计 1, for start:increment:end 若默认步长为1,则为 for start:end ———— end while condition ———— end ...
- JS错误记录 - dom操作 - 排序
本次练习错误总结: 1. for循环要套到按钮的onclick里面,否则onclick点击事件无法依次执行. 2. var n1, var n2 这两个变量是arr.sort排序使用的,所以应该放在s ...
- CMDB学习之二数据采集
首先也要调用插件的方式,来写采集数据插件,在src目录下创建一个插件 plugins ,然后在plugins下创建disk.py ,memory.py, network.py等等 src plugin ...
- Linux 创建新用户并添加到sudo用户组
附上一份相当奢华的文档: https://www.cnblogs.com/jxhd1/p/6528574.html 添加用户到组 usermod -a -G sudo newone
- FZU 1921 栀子花开
栀子花开 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on FZU. Original ID: 19216 ...