Android - 如何设置首次选择的操作栏选项卡?

hyp*_*ris 1 android android-actionbar android-tabs

这是我的代码:

    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);
Run Code Online (Sandbox Code Playgroud)

如何将"UserHome"设置为显示/选择的第一个选项卡?我现在想要它在中间.因此,当我的"TabActivity"开始时,它将是这样的:朋友 - 主页 - 高分榜

jim*_*thy 5

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

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