我在我的应用中使用了导航抽屉。当用户点击任何项目时,它会转到另一个活动,但当用户回到抽屉页面时,它仍然处于打开状态。如何在点击物品后关闭该抽屉。点击任何项目后关闭导航抽屉
2
A
回答
1
使用closeDrawer()
方法关闭抽屉,并启动抽屉监听器上的其他活动。
例如。
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
//Start your activity
}
1
您可以使用drawerLayout.closeDrawers();
关闭NavigationDrawer
你去到另一个活动
0
我想你错过closeDrawer()
上的导航项目的点击启动其他前只需要调用此方法之前Intent
drawerLayout.closeDrawer(GravityCompat.END);
0
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
// Create a new fragment and specify the fragment to show based on nav item clicked
Fragment fragment = null;
Class fragmentClass = null;
if (id == R.id.nav_item1) {
fragmentClass = home.class;
// Handle the camera action
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
if(fragmentClass.newInstance() instanceof Fragment) {
fragment = (Fragment) fragmentClass.newInstance();
if (fragmentClass.getSimpleName().equals("home")) {
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.home_layout, fragment).commit();
// Highlight the selected item has been done by NavigationView
item.setChecked(true);
// Set action bar title
setTitle(item.getTitle());
// Close the navigation drawer
drawer.closeDrawers();
}
}
相关问题
- 1. 导航抽屉关闭点击
- 2. 我的导航点击菜单项后抽屉不关闭?
- 3. 如何打开任何片段后抽屉式导航栏点击抽屉式导航栏项目后立即关闭
- 4. 片段不会改变后,项目点击导航抽屉
- 5. 导航抽屉项目
- 6. 导航抽屉 - 禁用点击抽屉后面的物品
- 7. 关闭groupItem上的导航抽屉点击在exapanablelistview
- 8. 导航抽屉关闭空的空间点击
- 9. 如何添加项目动态点击导航抽屉
- 10. 如何让导航抽屉完全不关闭左侧抽屉?
- 11. 如何在点击项目菜单时关闭抽屉菜单?
- 12. 平滑关闭导航抽屉
- 13. 导航抽屉关闭不动画
- 14. 关闭导航抽屉箭头动画
- 15. 关闭导航抽屉没有动画
- 16. 关闭屏幕导航抽屉
- 17. 导航抽屉没有关闭
- 18. 关闭Xamarin表单导航抽屉
- 19. 导航抽屉关闭错误
- 20. Android导航抽屉不能点击一个项目
- 21. 在抽屉式导航栏项目点击弹出窗口
- 22. 导航抽屉项目ByDefault选中不点击andorid
- 23. 在导航抽屉项目上开始新活动点击
- 24. 更改导航抽屉项目上的屏幕点击
- 25. 新的活动不启动时,点击导航抽屉项目
- 26. 导航抽屉RecyclerView Items点击活动
- 27. 点击更改导航抽屉菜单
- 28. 试图在点击导航抽屉中的项目后启动地图活动
- 29. 通过单击ImageButton关闭android导航抽屉
- 30. 添加项目到导航抽屉
在呼叫意图之前关闭抽屉。如需更多帮助,请发布您的代码。 –
我已发布解决方案尝试一下。如果仍然没有解决,那么在这里发布您的代码 –
[如何关闭导航抽屉时,从它按下一个项目?]的可能重复(http://stackoverflow.com/questions/19194526/how-to-close-navigation-drawer -when-an-item-is-press-from-it) –