Using a TabLayout without a ViewPager

suggest change

Most of the time a TabLayout is used together with a ViewPager, in order to get the swipe functionality that comes with it.

It is possible to use a TabLayout without a ViewPager by using a TabLayout.OnTabSelectedListener.

First, add a TabLayout to your activity’s XML file:

    android:id="@+id/tabLayout" />

For navigation within an Activity, manually populate the UI based on the tab selected.

TabLayout tabLayout = (TabLayout) findViewById(;
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
    public void onTabSelected(TabLayout.Tab tab) {
        int position = tab.getPosition();
        switch (tab.getPosition()) {
            case 1:
                    .replace(, new ChildFragment()).commit();
            // Continue for each tab in TabLayout

    public void onTabUnselected(TabLayout.Tab tab) {


    public void onTabReselected(TabLayout.Tab tab) {


Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents