ActionBarSherlock:标签失去自定义视图在横向模式 [英] ActionBarSherlock: Tab loses custom view in landscape mode

查看:105
本文介绍了ActionBarSherlock:标签失去自定义视图在横向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ActionBarSherlock与 NAVIGATION_MODE_TABS 。每个标签包含一个自定义视图。虽然它看起来不错纵向模式,如果选项卡显示为下拉列表(由机器人自动完成),也有在横向模式下诸多问题:

I'm using ActionBarSherlock with NAVIGATION_MODE_TABS. Each tab contains a custom view. While it looks fine in portrait mode, there are numerous problems in landscape mode if the tabs are displayed as drop down list (automatically done by Android):

  • 的Andr​​oid 4.x版:选择的选项卡未在操作栏显示(见图片,红圈)。使用内置的动作条从Android SDK直接。
  • 在当前同样的情况
  • 安卓2.X:所选择的选项卡未在操作栏显示。当我就降下来点击,整个下拉消失,我得到空标签代替。
  • Android 4.x: The selected tab is not shown in the Action Bar (see image, red circle). The same happens when using the built-in Action Bar from the Android SDK directly.
  • Android 2.x: The selected tab is not shown in the Action Bar. As soon as I click on the drop down, the whole drop down vanishes and I get empty tabs instead.

一切工作正常,如果我不使用自定义视图。我的code。该图像上创建的动作条(保持简单的目的):

Everything works fine if I do not use a custom view. My code that creates the ActionBar on the image (kept simple on purpose):

getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
for (int i = 0; i < 7; i++) {
    ActionBar.Tab tab = getActionBar().newTab();
    TextView view = new TextView(this);
    view.setText("This is tab " + (i + 1));
    tab.setCustomView(view);
    tab.setTabListener(this);
    getActionBar().addTab(tab);
}

我是不是做错了什么?

Am I doing something wrong?

修改:为了澄清, getSupportActionBar()是present在原来的code和从ActionBarSherlock操作栏是从所描述的问题,做工精细分开。我用code样品上方,以表明第一个问题(所选选项卡中的操作栏未显示)也使用了内置的操作栏时present。很抱歉的混乱。

EDIT: To clarify, getSupportActionBar() is present in the original code and the Action Bar from ActionBarSherlock is working fine apart from the described issues. I used the code sample above to illustrate that the first issue (selected tab not shown in Action Bar) is also present when using the built-in Action Bar. Sorry for the confusion.

推荐答案

通过ActionBarSherlock你应该使用 getSupportActionBar(),以便为它工作在2.X

With ActionBarSherlock you should be using getSupportActionBar() in order for it to work on 2.x

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);
}

文本颜色是无论是从查看您所申请的选项卡,或从一个主题,你所申请的活动水平自定义来了。

The text color is either coming from the custom view you are applying to the Tab or from a theme you are applying at the Activity level.

这篇关于ActionBarSherlock:标签失去自定义视图在横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆