A sample app for Bottom Navigation View with ViewPager
For connecting BottomNavigationView with ViewPager, you need to follow thesesteps
First, you need to create an application with latest Design Support Library(25) to your build.gradle to use BottomNavigationView.
Then add all the necessary resources ( color, drawable’s ) to the resource directory.
Create a view with ViewPager and BottomNavigationView
Create necessary fragments for each tab on the viewpager.
Then setup the viewpager using fragments and viewpager adapter.
Add OnNavigationItemSelectedListener for BottomNavigationView, and override OnNavigationItemSelected method with the relevant action.
Once done with the previous step add OnPageChangeListener to the ViewPager and override the PageSelected method. The magic happens here, the following code selects the relevant item in the BottomNavigationView.
@Override public void onPageSelected(int position) { if (prevMenuItem != null) { prevMenuItem.setChecked(false); } else { bottomNavigationView.getMenu().getItem(0).setChecked(false); } bottomNavigationView.getMenu().getItem(position).setChecked(true); prevMenuItem = bottomNavigationView.getMenu().getItem(position); }
For more information, check out my detailed guide here : http://droidmentor.com/bottomnavigationview-with-viewpager-android
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。