<?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" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" /> <androID.support.design.Widget.NavigationVIEw androID:ID="@+ID/nav_vIEw2" androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:layout_gravity="end" androID:fitsSystemwindows="true" app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer1" /></androID.support.v4.Widget.DrawerLayout>
任何帮助都会非常值得一提.
解决方法 好的,我找到了答案.我们可以通过以下行从工具栏中获取按钮,button btnStart = (button) findVIEwByID(R.ID.btnStart);button btnEnd = (button) findVIEwByID(R.ID.btnEnd);
点击开始按钮,我们可以通过跟随听众打开并隐藏左抽屉,
btnStart.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (drawer.isDrawerOpen(GravityCompat.START)) drawer.closeDrawer(GravityCompat.START); else drawer.openDrawer(GravityCompat.START); }});
点击结束按钮,我们可以通过跟随听众打开并隐藏右抽屉,
btnEnd.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { if (drawer.isDrawerOpen(GravityCompat.END)) drawer.closeDrawer(GravityCompat.END); else drawer.openDrawer(GravityCompat.END); }});
我们的onBackpressed方法将是
public voID onBackpressed() { DrawerLayout drawer = (DrawerLayout) findVIEwByID(R.ID.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else if (drawer.isDrawerOpen(GravityCompat.END)) { drawer.closeDrawer(GravityCompat.END); } else { super.onBackpressed(); }}
如果抽屉处于打开状态,这也用于关闭抽屉.
有关更多信息,请参阅我的博客http://v4all123.blogspot.in/2016/03/simple-example-of-navigation-view-on.html
总结以上是内存溢出为你收集整理的android – 两侧的NavigationView全部内容,希望文章能够帮你解决android – 两侧的NavigationView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)