Skip to content

TabLayout, TabSlider, Tab with CustomIcons and ViewPagerAdapter with Fragments

Notifications You must be signed in to change notification settings

amansharma-dev/TabLayout_SliderCustom_Icons_ViewPager

Repository files navigation

SliderTabLayout with Icons.

Hello, I have focused on the implementation of Sliding TabLayout with Icons attahed to it, in which you will also get to know how ViewPager & FragmentPagerAdapter plays an important role to provide more functionality to the TabLayouts.

What you will learn.

  • Extend FragmentPagerAdapter.

  • Implementation of design support library in build.gradle(Module:app).

  • Remove ActionBar, check res->values->styles.xml.

  • Proper use of text in strings.xml file in a project, check res->values.

Note to Novice

In MainActivity onCreate method:

Remember to use setupViewPager() before setupTabIcons() otherwise you will get a null pointer exception on runtime.

  • setupViewPager();
{
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        viewPagerAdapter.addFragment(new One(),"Frag One");
        viewPagerAdapter.addFragment(new Two(),"Frag Two");
        viewPagerAdapter.addFragment(new Three(),"Frag Three");
        viewPagerAdapter.addFragment(new Four(),"Frag Four");
        viewPagerAdapter.addFragment(new Five(),"Frag Five");
        viewPagerAdapter.addFragment(new Six(),"Frag Six");

        viewPager.setAdapter(viewPagerAdapter);
        }
  • setupTabIcons();
{
        tabLayout.getTabAt(0).setIcon(tabIcons[0]);
        tabLayout.getTabAt(1).setIcon(tabIcons[1]);
        tabLayout.getTabAt(2).setIcon(tabIcons[2]);
        tabLayout.getTabAt(3).setIcon(tabIcons[3]);
        tabLayout.getTabAt(4).setIcon(tabIcons[4]);
        tabLayout.getTabAt(5).setIcon(tabIcons[5]);
        }

Support 👍

Instagram

Thank You!