navigation view 使用
来源:互联网 发布:linux设备驱动开发详解 编辑:程序博客网 时间:2024/06/03 23:41
使用NavigationView,一般是在DrawerLayout中,实现侧滑菜单。
实际示例:
<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/main_drawer" android:fitsSystemWindows="true" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout ...> <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_gravity="start" android:fitsSystemWindows="true" app:menu="@menu/main_menu"> </android.support.design.widget.NavigationView></android.support.v4.widget.DrawerLayout>
在相应的activity中,添加对侧滑菜单的点击监听:
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { item.setChecked(true); mDrawer.closeDrawer(Gravity.START); switch (item.getItemId()) { } return true; } });
注意:要使setNavigationItemSelectedListener的监听生效,需要将NavigationView放在父组件中的第一位以后,即NavigationView不能放在第一位(最上层)。
When you make a xml, you should write down NavigationView after BaseLayout(FrameLayout, LinearLayout, etc..)<DrawerLayout> <FrameLayout /> <NavigationView /></DrawerLayout>
来自stackoverflow的回答
阅读全文
0 0
- Navigation View的使用
- navigation view 使用
- Navigation View的使用详解
- react-navigation Navigation使用
- Design Support Library (I): Navigation View的使用
- Page view Navigation
- Navigation 使用
- Navigation View---头部点击事件
- Navigation View--抽屉式布局
- Navigation View的使用详解 (有menu的xml和点击事件)
- Navigation Drawer的使用
- Android Navigation的使用
- react-navigation 简单使用
- react-navigation使用
- react-navigation使用技巧
- react-navigation使用
- react-navigation使用心得
- React Navigation基础使用
- 在windows下配置pthread
- sql内连接外链接做链接有了链接
- Android-Glide使用
- 使用JVisualVM查找并定位Java程序CPU使用率过高问题
- finally关键字
- navigation view 使用
- 微信内置浏览器关闭本窗口
- Linux安装Oracle12C 过程及遇到的问题
- git rm --cache忽略已经提交的文件和如何恢复
- java post json
- Java单例模式
- 关于回调函数和钩子函数基础知识的整理
- python接口自动化5-Json数据处理
- 全文检索之lucene入门