[英]Navigation drawer for android app
我在https://developer.android.com/training/implementing-navigation/nav-drawer.html上找到了一个导航抽屉示例,但问题是,在抽屉之间切换时会显示图像,我想在类之间进行切换有帮助吗?
The example isn't simply switching images. 该示例不只是切换图像。 If you look closer you will see that it's creating a new
Fragment
for ever item selected. 如果您仔细看,您会发现它正在为选定的所有项目创建一个新的
Fragment
。 That is the component that you would most likely use when you say "switch between classes". 这是您说“在类之间切换”时最有可能使用的组件。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.