在我无法替换当前片段的新支持设计库上,请查看下面的代码。虽然 Toasts 正在工作并显示在屏幕上。每当我要单击导航抽屉上的任何项目时,我都会出现空白屏幕
private void setupDrawerContent(NavigationView navigationView) {
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.navigation_home:
getFragmentManager().beginTransaction().replace(R.id.container, new HomeFragment()).commit();
Toast toast;
toast = Toast.makeText(getApplicationContext(), "Home", Toast.LENGTH_LONG);
toast.show();
case R.id.navigation_settings:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getFragmentManager().beginTransaction().replace(R.id.container, new SettingsFragmentLollipop()).commit();
} else {
getFragmentManager().beginTransaction().replace(R.id.container, new SettingsFragment()).commit();
}
Toast toast1;
toast1 = Toast.makeText(getApplicationContext(), "Settings", Toast.LENGTH_LONG);
toast1.show();
}
menuItem.setChecked(true);
mDrawerLayout.closeDrawers();
return true;
}
});
}