如何以编程方式设置选定的选项卡SlidingTabLayout

时间:2015-04-05 20:24:50

标签: java android

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

1 个答案:

答案 0 :(得分:1)

@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);
}