在特定标签栏中打开应用程序
Open the app in a specific tabbar
我有一个带导航抽屉和 6 个寻呼机滑动选项卡的应用程序。当我启动应用程序时,左侧选项卡会打开。我想让它打开特定选项卡,我该怎么做?谢谢。
这是 ViewPagerFragment :
mTabs.add(new SamplePagerItem(0, getString(R.string.tab_one), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(1, getString(R.string.tab_two), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(2, getString(R.string.tab_three), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(3, getString(R.string.tab_four), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(4, getString(R.string.tab_five), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(5, getString(R.string.tab_six), getResources().getColor(Utils.colors[4]), Color.GRAY));
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.viewpager_fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
ViewPager mViewPager = (ViewPager) view.findViewById(R.id.mPager);
mViewPager.setOffscreenPageLimit(4);
mViewPager.setAdapter(new ViewPagerAdapter(getChildFragmentManager(), mTabs));
SlidingTabLayout mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.mTabs);
mSlidingTabLayout.setBackgroundResource(R.color.white);
mSlidingTabLayout.setViewPager(mViewPager);
mSlidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return mTabs.get(position).getIndicatorColor();
}
@Override
public int getDividerColor(int position) {
return mTabs.get(position).getDividerColor();
}
});
}
}
你可以试试这个
mViewPager.setCurrentItem(position);
我有一个带导航抽屉和 6 个寻呼机滑动选项卡的应用程序。当我启动应用程序时,左侧选项卡会打开。我想让它打开特定选项卡,我该怎么做?谢谢。
这是 ViewPagerFragment :
mTabs.add(new SamplePagerItem(0, getString(R.string.tab_one), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(1, getString(R.string.tab_two), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(2, getString(R.string.tab_three), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(3, getString(R.string.tab_four), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(4, getString(R.string.tab_five), getResources().getColor(Utils.colors[4]), Color.GRAY));
mTabs.add(new SamplePagerItem(5, getString(R.string.tab_six), getResources().getColor(Utils.colors[4]), Color.GRAY));
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.viewpager_fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
ViewPager mViewPager = (ViewPager) view.findViewById(R.id.mPager);
mViewPager.setOffscreenPageLimit(4);
mViewPager.setAdapter(new ViewPagerAdapter(getChildFragmentManager(), mTabs));
SlidingTabLayout mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.mTabs);
mSlidingTabLayout.setBackgroundResource(R.color.white);
mSlidingTabLayout.setViewPager(mViewPager);
mSlidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return mTabs.get(position).getIndicatorColor();
}
@Override
public int getDividerColor(int position) {
return mTabs.get(position).getDividerColor();
}
});
}
}
你可以试试这个
mViewPager.setCurrentItem(position);