側拉和導航欄的基本邏輯
//配置抽屜
private AppBarConfiguration mAppBarConfiguration;
DrawerLayout drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.nav_home, R.id.nav_gallery, R.id.nav_slideshow)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
//添加抽屜功能 使得actionbar 能有抽屜按鈕 具備導航功能
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
//使得點擊可以跳轉
NavigationUI.setupWithNavController(navigationView, navController);
setupActionBarWithNavController方法
Sets up the ActionBar returned by {@link AppCompatActivity#getSupportActionBar()} for use
with a {@link NavController}.
因爲要去把導航視圖和導航控制器連接起來所有要去執行這個方法
setupWithNavController方法
Sets up a {@link NavigationView} for use with a {@link NavController}. This will call
{@link #onNavDestinationSelected(MenuItem, NavController)} when a menu item is selected.
The selected item in the NavigationView will automatically be updated when the destination
changes.
爲了把視圖和導航連接起來
Tablayout加上viewpager
基本的步驟
/**
* 1 寫viewpager的適配器
* 2 new viewpagerAdapter 後綁定viewpager
* 3 viewPager.setAdapter(sectionsPagerAdapter);
* 4 首先綁定Tablayout
* 5 tabs.setupWithViewPager(viewPager);
* @param savedInstanceState
*/