我只是简单地在github上复制了一个代码,效果很好,但是我无法实现实现允许我在不同片段之间导航的方法。当我单击下部导航栏中的第一个图标时,我要转到片段A;单击第二个图标时,我要转到片段B,依此类推。我该怎么办?
这是我正在使用的代码
public class BottomBarActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bottom_bar);
ArrayList<ScreenSlidePageFragment> fragList = new ArrayList<>();
fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.home), R.color.red_inactive));
fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.search), R.color.blue_inactive));
fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.likes), R.color.blue_grey_inactive));
fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.notification), R.color.green_inactive));
fragList.add(ScreenSlidePageFragment.newInstance(getString(R.string.profile), R.color.purple_inactive));
ScreenSlidePagerAdapter pagerAdapter = new ScreenSlidePagerAdapter(fragList, getSupportFragmentManager());
final BubbleNavigationLinearView bubbleNavigationLinearView = findViewById(R.id.bottom_navigation_view_linear);
final ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(pagerAdapter);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
}
@Override
public void onPageSelected(int i) {
bubbleNavigationLinearView.setCurrentActiveItem(i);
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
bubbleNavigationLinearView.setNavigationChangeListener(new BubbleNavigationChangeListener() {
@Override
public void onNavigationChanged(View view, int position) {
viewPager.setCurrentItem(position, true);
}
});
}
}