简体   繁体   English

如何设置ActionBar Sherlock标签?

[英]How to set up an ActionBar Sherlock Tab?

I'm switching my App's Tab (API 7) to the one's used in the Action Bar Sherlock because of the design, but I don't know how to set this up. 由于设计原因,我将应用程序的选项卡(API 7)切换到了Action Bar Sherlock中使用的选项卡,但我不知道如何设置。

That's how I used to do: 那是我过去的工作方式:

    tabH = (TabHost) findViewById(R.id.tabhost);

    tabH.setup();

    TabSpec espec = tabH.newTabSpec("tabONE");
    espec.setContent(R.id.tbhot);
    espec.setIndicator("A");
    tabH.addTab(espec);

    espec = tabH.newTabSpec("tabTWO");
    espec.setContent(R.id.tbrecente);
    espec.setIndicator("B");
    tabH.addTab(espec);

    espec = tabH.newTabSpec("tabTHREE");
    espec.setContent(R.id.tbcreate);
    espec.setIndicator("C");
    tabH.addTab(espec);

And now that's what I'm doing: 现在这就是我正在做的:

getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (int i = 1; i <= 3; i++) {
        ActionBar.Tab tab = getSupportActionBar().newTab();
        if (i == 1)
            tab.setText("A");
        else if(i == 2)
            tab.setText("B");
        else if (i == 3)
            tab.setText("C");
        tab.setTabListener(this);
        getSupportActionBar().addTab(tab);
    }

That works, but I don't know how to set the Content, so all tabs have the same thing in it. 那行得通,但是我不知道如何设置内容,因此所有选项卡中都有相同的内容。 How do I do it? 我该怎么做?

Also, my other tab was at the bottom of the layout. 另外,我的另一个选项卡位于布局的底部。 Is it possible to set this one at the bottom too? 是否可以将其设置在底部? I believe that if I could set the TabHost in the new tab, it will be in the bottom too, so the question is, how to set the tabhost here? 我相信,如果可以在新选项卡中设置TabHost,它也将位于底部,因此问题是,如何在此处设置TabHost?

I typically use fragments for the content. 我通常使用片段作为内容。 You have to implement the ActionBar.TabListener and adjust your content there, but it's pretty easy. 您必须实现ActionBar.TabListener并在那里调整内容,但这很容易。 You can add all your fragments at the beginning and show/hide them, or replace the current fragment. 您可以在开头添加所有片段并显示/隐藏它们,或替换当前片段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM