我在我的應用中使用了導航抽屜。當用戶點擊任何項目時,它會轉到另一個活動,但當用戶回到抽屜頁面時,它仍然處於打開狀態。如何在點擊物品後關閉該抽屜。點擊任何項目後關閉導航抽屜
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) –