如何使用Google的SlidingTabLayout以编程方式更改所选标签?

最佳答案

@Bind(R.id.pager) ViewPager mViewPager;
@Bind(R.id.tabs) SlidingTabLayout tabs;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_team_details);
   ButterKnife.bind(this);

   //get this value from savedInstanceState
   int tabThatNeedsToBeSelected = 3;

   myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),params);
   mViewPager.setAdapter(myFragmentPagerAdapter);
   tabs.setViewPager(mViewPager);
   mViewPager.setCurrentItem(tabThatNeedsToBeSelected);
}

09-18 10:08