我见过许多例子,但我无法理解如何在平板电脑中打开导航抽屉。我正在使用这个导航抽屉https://github.com/kanytu/android-material-drawer-template。我将不得不创建另一个xml文件?在OnCreate()中我需要添加什么样的代码?
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 :(得分:0)
我没有准确的知识,但解决方法可能是为没有DrawerLayout的大型设备制作不同的xml文件,因此当它在平板电脑上运行时它将返回null并且代码中没有其他布尔值。将使编码部分非常简单:-) kudos!