我找到了一个导航抽屉样本 https://developer.android.com/training/implementing-navigation/nav-drawer.html 但事情是,当抽屉之间切换时,它会切换图像,我希望在课间切换任何帮助吗?
答案 0 :(得分:0)
该示例不仅仅是切换图像。如果你仔细观察,你会发现它为所选的项目创建了一个新的Fragment
。当您说“在类之间切换”时,这是您最有可能使用的组件。
private void selectItem(int position) {
// Create a new fragment and specify the planet to show based on position
Fragment fragment = new PlanetFragment();
Bundle args = new Bundle();
args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
fragment.setArguments(args);
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
// Highlight the selected item, update the title, and close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPlanetTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}