我正在运行来自Actionbersherlock示例的演示,并注意到标签总是位于操作栏内,如图所示。 我该如何解决? 日Thnx。
public class TabNavigation extends SherlockActivity implements ActionBar.TabListener { private TextView mSelected; @Override public void onCreate(Bundle savedInstanceState) { setTheme(SampleList.THEME); //Used for theme switching in samples super.onCreate(savedInstanceState); setContentView(R.layout.tab_navigation); mSelected = (TextView)findViewById(R.id.text); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); for (int i = 1; i <= 3; i++) { ActionBar.Tab tab = getSupportActionBar().newTab(); tab.setText("Tab " + i); tab.setTabListener(this); getSupportActionBar().addTab(tab); } } @Override public void onTabReselected(Tab tab, FragmentTransaction transaction) { } @Override public void onTabSelected(Tab tab, FragmentTransaction transaction) { mSelected.setText("Selected: " + tab.getText()); } @Override public void onTabUnselected(Tab tab, FragmentTransaction transaction) { }}
代码从这里:
https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock-samples/demos/src/com/actionbarsherlock/sample/demos/TabNavigation.javaI was running the demo from Actionbersherlock samples and noticed the tabs were always inside the actionbar as in the picture. How do I fix this? thnx.
public class TabNavigation extends SherlockActivity implements ActionBar.TabListener { private TextView mSelected; @Override public void onCreate(Bundle savedInstanceState) { setTheme(SampleList.THEME); //Used for theme switching in samples super.onCreate(savedInstanceState); setContentView(R.layout.tab_navigation); mSelected = (TextView)findViewById(R.id.text); getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); for (int i = 1; i <= 3; i++) { ActionBar.Tab tab = getSupportActionBar().newTab(); tab.setText("Tab " + i); tab.setTabListener(this); getSupportActionBar().addTab(tab); } } @Override public void onTabReselected(Tab tab, FragmentTransaction transaction) { } @Override public void onTabSelected(Tab tab, FragmentTransaction transaction) { mSelected.setText("Selected: " + tab.getText()); } @Override public void onTabUnselected(Tab tab, FragmentTransaction transaction) { }}
Code From here:
https://github.com/JakeWharton/ActionBarSherlock/blob/master/actionbarsherlock-samples/demos/src/com/actionbarsherlock/sample/demos/TabNavigation.java最满意答案
根据操作栏选项卡指南 :
系统根据不同的屏幕尺寸调整操作栏选项卡 - 当屏幕足够宽时将它们放置在主操作栏中,或者当屏幕太窄时将其放置在单独的栏(称为“堆叠操作栏”)中
由于ActionBarSherlock模仿平台行为,如果有足够的空间,选项卡将显示在操作栏中。 您无法按其他 答案强制堆叠操作栏模式。
Per the Action Bar Tabs guide:
the system adapts the action bar tabs for different screen sizes—placing them in the main action bar when the screen is sufficiently wide, or in a separate bar (known as the "stacked action bar") when the screen is too narrow
As ActionBarSherlock mimics the platform behavior, tabs will appear in the Action Bar if there is enough space. You cannot force the stacked action bar pattern as per other answers.
更多推荐
发布评论