java Android 4+actionbar标签在首次发布时显示为下拉列表,以防止?
我正在开发一款Android 4+应用程序,它使用ActionBar标签导航安卓.support.v4.view.ViewPager
。除了安装后第一次启动应用程序外,这一切都很好。在这种情况下,选项卡显示为下拉列表
这是主要活动的布局:
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.v4.widget.DrawerLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
xmlns:tools="http://schemas.安卓.com/tools"
安卓:id="@+id/drawer_layout"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
tools:context=".MainActivity" >
<安卓.support.v4.view.ViewPager
安卓:id="@+id/pager"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"/>
<ListView
安卓:id="@+id/left_drawer"
安卓:layout_width="240dp"
安卓:layout_height="match_parent"
安卓:layout_gravity="start"
安卓:choiceMode="singleChoice"
style="@style/NavigationDrawerListView" />
<ListView
安卓:id="@+id/right_drawer"
安卓:layout_width="240dp"
安卓:layout_height="match_parent"
安卓:layout_gravity="end"
安卓:divider="@安卓:color/transparent"
安卓:dividerHeight="0dp"
style="@style/ShortcutsListView" />
</安卓.support.v4.widget.DrawerLayout>
使用init代码main活动。爪哇
protected void onCreate(Bundle savedInstanceState) {
...
// TabBar
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager = (ViewPager)findViewById(R.id.pager);
viewPager.setAdapter(sectionsPagerAdapter);
currentPageIndex = (savedInstanceState != null ? savedInstanceState.getInt(CURRENT_PAGE_INDEX_KEY, -1) : -1 );
viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
getActionBar().setSelectedNavigationItem(position);
updateCurrentPageIndex(position);
}
});
// ActionBar
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
ActionBar.TabListener tabListener = new ActionBar.TabListener() {
public void onTabSelected(Tab tab, 安卓.app.FragmentTransaction arg1) {
viewPager.setCurrentItem(tab.getPosition());
}
public void onTabReselected(Tab arg0, 安卓.app.FragmentTransaction arg1) { }
public void onTabUnselected(Tab arg0, 安卓.app.FragmentTransaction arg1) { }
};
actionBar.addTab(actionBar.newTab()
.setText(R.string.MainPageTitle)
.setTabListener(tabListener));
actionBar.addTab(actionBar.newTab()
.setText(R.string.ContactsPageTitle)
.setTabListener(tabListener));
actionBar.addTab(actionBar.newTab()
.setText(R.string.SettingsPageTitle)
.setTabListener(tabListener));
actionBar.addTab(actionBar.newTab()
.setText(R.string.MessagePageTitle)
.setTabListener(tabListener));
// http://stackoverflow.com/questions/14672984/
// Set NavigationMode AFTER alle tabs have been added
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
...
}
据我所知,第一次发射是唯一的区别。但我不知道这会如何影响标签
你知道如何使用标签,而不使用下拉列表吗
# 1 楼答案
使用此项目而不是standart
https://github.com/astuetz/PagerSlidingTabStrip
# 2 楼答案
首先,操作栏标签在一年前就被弃用了
第二,you have never had control whether action bar tabs show up as tabs versus a drop-down list
我建议您使用其他一些选项卡解决方案,无论是来自SDK的设计支持库的} 、
TabLayout
、third-party tabs associated with a ^{FragmentTabHost
等等