2017-01-13 60 views
-1

我正在開發一個帶導航抽屜的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); 
} 

但它不工作! 。一旦申請開始,如何隱藏它?

+3

抽屜通常apears隱藏在活動。你確定你沒有要求它在代碼中的某個地方出現嗎? –

+0

是的,我確定。 –

回答

6

mDrawerLayout.closeDrawer(GravityCompat.START);

+0

感謝您的回答 –

1

嗨ü可以使用下面的代碼:

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 
    drawer.closeDrawer(GravityCompat.START); 
相關問題