底部有五个项目导航栏。当从第三个开始的项目返回到前两个时,它将闪回。我只在第一项中使用了幻灯片。
在mainactivity中使用bottomnavigationview
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.tab_one:
viewPager.setCurrentItem(0);
return true; //返回true,否则tab按钮不变色,未被选中
case R.id.tab_two:
viewPager.setCurrentItem(1);
return true;
case R.id.tab_three:
viewPager.setCurrentItem(2);
return true;
case R.id.tab_four:
viewPager.setCurrentItem(3);
return true;
case R.id.tab_five:
viewPager.setCurrentItem(4);
return true;
default:
break;
}
return false;
在碎片中使用滑动布局
fragments.add(new AFFragment());
fragments.add(new ASFragment());
fragments.add(new ATFragment());
tabLayout.setViewPager(viewPager,titles, getActivity(),fragments);
> java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
at com.flyco.tablayout.SlidingTabLayout$InnerPagerAdapter.getPageTitle(SlidingTabLayout.java:867)
at com.flyco.tablayout.SlidingTabLayout.notifyDataSetChanged(SlidingTabLayout.java:232)
at com.flyco.tablayout.SlidingTabLayout.setViewPager(SlidingTabLayout.java:222)
at com.example.running.ui.run.AFragment.setupWithViewPager(AFragment.java:48)
at com.example.running.ui.run.AFragment.onCreateView(AFragment.java:39)
[enter image description here][1]
[enter image description here][2]
[enter image description here][3]
[enter image description here][4]
[1]: https://i.stack.imgur.com/8gwbQ.png
[2]: https://i.stack.imgur.com/ktGGH.png
[3]: https://i.stack.imgur.com/5rE3i.png
[4]: https://i.stack.imgur.com/COPVC.png
暂无答案!
目前还没有任何答案,快来回答吧!