Android ActionBar tabs set initially selected tab

后端 未结 6 1161
-上瘾入骨i
-上瘾入骨i 2020-12-15 05:53

I have noticed that when using

actionBar.setSelectedNavigationItem(x)

in the onCreate() method of my Activity, the tab item at position 0

6条回答
  •  死守一世寂寞
    2020-12-15 05:58

    Percy Vega's reply seems to be the best working solution.

        for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
    
            boolean preselected = (i == ErrorDetails.tab_id);
            actionBar.addTab(
                    actionBar.newTab()
                            .setText(mSectionsPagerAdapter.getPageTitle(i))
                            .setTabListener(this),preselected);
        }
    

提交回复
热议问题