1

这是我的代码:

    Tab tab = actionBar
            .newTab()
            .setText(R.string.friends)
            .setTabListener(
                    new TabListener<FriendsFragment>(this, "friends_list",
                            FriendsFragment.class));
    actionBar.addTab(tab);

    tab = actionBar
            .newTab()
            .setText(R.string.home)
            .setTabListener(
                    new TabListener<UserHomeFragment>(this, "user_home",
                            UserHomeFragment.class));
    actionBar.addTab(tab);

    tab = actionBar
            .newTab()
            .setText(R.string.highscores)
            .setTabListener(
                    new TabListener<HighscoresFragment>(this, "highscores",
                            HighscoresFragment.class));
    actionBar.addTab(tab);

如何将“UserHome”设置为显示/选择的第一个选项卡?我想像现在这样在中间。因此,当我的“TabActivity”启动时,它会是这样的:Friends - Home - Highscores

4

1 回答 1

5

有几个选项,当前实现最简单的方法是在使用ActionBar#addTab(Tab tab, boolean setSelected)将选项卡添加到操作栏时将其设置为选定选项卡。

或者,您可以使用ActionBar#setSelectedNavigationItem(int position)设置选择。

于 2012-07-28T19:37:23.113 回答