【问题标题】:How to display Navigation Drawer below Viewpager tabs?如何在 Viewpager 选项卡下方显示导航抽屉?
【发布时间】:2015-02-02 07:55:53
【问题描述】:
我的导航抽屉工作正常!!
但我想修改它,例如在 viewpager 选项卡下方显示抽屉。
我通过将导航抽屉添加到我的活动中来使用它,然后访问它,但这次场景不同,我想在选项卡下方显示抽屉。
我可以在片段布局中添加导航抽屉并从片段类访问它,或者如果它不可能/不推荐,那么我该如何实现。
问题理解请参考附件截图。
提前致谢。
【问题讨论】:
标签:
android
android-fragments
android-viewpager
navigation-drawer
【解决方案1】:
您有两种方法可以实现这一目标。
1.方法一,可持续的
在您的布局中使用 support.v7.Toolbar 并正确放置 NavigationDrawer 将满足您的需要。此外,它更耐用。
2。方法二:老款
使用 ActionBar 选项卡见http://developer.android.com/training/implementing-navigation/lateral.html#tabs
主要部分是
final ActionBar actionBar = getActionBar();
...
// Specify that tabs should be displayed in the action bar.
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create a tab listener that is called when the user changes tabs.
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
// show the given tab
}
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
// hide the given tab
}
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
// probably ignore this event
}
};
// Add 3 tabs, specifying the tab's text and TabListener
for (int i = 0; i < 3; i++) {
actionBar.addTab(
actionBar.newTab()
.setText("Tab " + (i + 1))
.setTabListener(tabListener));
}