2015-06-17 70 views
0

我見過很多例子左右,但我不明白爲什麼有抽屜式導航總是在平板電腦開放。我正在使用此導航抽屜https://github.com/kanytu/android-material-drawer-template。我將不得不創建另一個XML文件?並在OnCreate()我需要添加什麼樣的代碼?的Android導航抽屜總是打開的平板電腦

public class MainActivity extends AppCompatActivity implements NavigationDrawerCallbacks { 

    private Toolbar mToolbar; 
    private NavigationDrawerFragment mNavigationDrawerFragment; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); 
     setSupportActionBar(mToolbar); 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 


     mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.fragment_drawer); 
     mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar); 
    } 
    @Override 
    public void onNavigationDrawerItemSelected(int position) { 
    FragmentManager fragmentManager = getFragmentManager(); 
    .. 
    .. 
    } 

    @Override 
    public void onBackPressed() { 
     if (mNavigationDrawerFragment.isDrawerOpen()) 
      mNavigationDrawerFragment.closeDrawer(); 
     else 
      super.onBackPressed(); 
    } 


     public void onResume() { 
      super.onResume(); 

     } 


} 

回答

0

我沒有準確的知識,而是一種解決方法可能是讓大型設備不同的XML文件,而不DrawerLayout所以當它運行在平板電腦上它會返回null,沒有其他的布爾將被neede代碼和這將使編碼部分非常簡單:-) kudos!