-1
A
回答
1
你有一些選擇。
1)打開activity_main.xml
和替換線,包括layout=content_main
與你真正想要的,而不是佈局。
2)只需加載片段onCreate
,就像您點擊導航抽屜時一樣。
0
去活動onCreate方法,並把這個
FragmentManager fm =getFragmentManager();
FragmentTransaction ft= fm.beginTransaction();
// the Second paramter is Object from your Fragment that you want to add it
ft.replace(R.id.activity_main ,fragmentObject );
ft.commit();
2
@Override
public boolean onNavigationItemSelected(MenuItem item) {
//calling the method displayselectedscreen and passing the id of selected menu
displaySelectedScreen(item.getItemId());
return true;
}
私人無效displaySelectedScreen(INT的itemId){
//creating fragment object
Fragment fragment = null;
//initializing the fragment object which is selected
switch (itemId) {
case R.id.nav_menu1:
fragment = new Menu1();
break;
case R.id.nav_menu2:
fragment = new Menu2();
break;
case R.id.nav_menu3:
fragment = new Menu3();
break;
}
//replacing the fragment
if (fragment != null) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fragment);
ft.commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}
中的onCreate()
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//add this line to display menu1 when the activity is loaded
displaySelectedScreen(R.id.nav_menu1);
相關問題
- 1. 抽屜導航和片段?
- 2. Android碎片導航抽屜
- 3. 導航抽屜與導航抽屜片段
- 4. 錯誤的片段和導航抽屜
- 5. 我的片段隱藏導航抽屜?
- 6. Android導航抽屜?
- 7. 機器人導航抽屜,片段
- 8. 在片段上添加導航抽屜
- 9. 添加按鈕,導航抽屜片段
- 10. 在片段上創建導航抽屜
- 11. 使用導航抽屜顯示片段
- 12. 防止抽屜式導航片段
- 13. Android的抽屜式導航欄 - 多段
- 14. 刷新導航抽屜碎片Android?
- 15. 瞭解android導航抽屜和碎片
- 16. 導航抽屜中的片段佈局Android應用程序
- 17. 的Android弧導航抽屜
- 18. 如何實現onBackPress從導航抽屜中的片段到MainActivity
- 19. Android片段管理器更改導航抽屜的行爲
- 20. 導航抽屜+滑動標籤裏面的片段Android
- 21. Android外包導航抽屜
- 22. Android導航抽屜級別
- 23. Android FLAG_KEEP_SCREEN_ON Fragment導航抽屜
- 24. Android導航抽屜新款
- 25. Android Studio 1.4導航抽屜
- 26. 上旋轉片段變動具有導航抽屜
- 27. 抽屜切換按鈕轉換與片段導航
- 28. 如何在使用導航抽屜的片段時在底部導航欄上添加導航抽屜?
- 29. Android重新載入導航抽屜片段
- 30. 如何將Recycleview項目移動到導航抽屜的片段?