Android ActionBar tabs set initially selected tab

后端 未结 6 1170
-上瘾入骨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 06:17

    you can use below statment in activtiy onStart method:

    protected void onStart() {
        super.onStart();
        actionBar.selectTab(mainTab);
    }
    

    which mainTab variable here is of type Tab. this way you need to define tabs as class-wide variables like this:

    Tab mainTab, tab2,tab3;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //add tabs to action bar
        ....
    }
    

提交回复
热议问题