我正在使用导航抽屉开发一个Android应用程序。一切正常。除了当我开始我的应用程序时,抽屉自动出现。我试图解决这个问题:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager()
.findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
mDrawerLayout);
// as a solution I added this if-statement
if(mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawers();
}
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
但它不起作用! 。一旦applilication开始,如何隐藏它?
答案 0 :(得分:6)
mDrawerLayout.closeDrawer(GravityCompat.START);
答案 1 :(得分:1)
您可以使用以下代码:
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);