title: Handle TabLayout tab click
body: <p>I have a Fragment with TabLayout and ViewPager in it:</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  tools:context="layout.LinksFragment"&gt;
  
  &lt;android.support.design.widget.TabLayout
      android:id="@+id/tab_layout_info"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="?attr/colorPrimary"
      android:elevation="6dp"
      android:minHeight="?attr/actionBarSize"
      android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /&gt;
  
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/pager_info"
      android:layout_width="match_parent"
      android:layout_height="fill_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"/&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>In my Fragment file, inside onCreateView() method, I set up both ViewPager and TabLayout:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View view = inflater.inflate(R.layout.fragment_links, container, false);
  
      TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout_info);
      tabLayout.addTab(tabLayout.newTab());
      tabLayout.addTab(tabLayout.newTab());
      tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
  
  
      ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager_info);
      PagerAdapterLinks adapter = new PagerAdapterLinks(getActivity().getSupportFragmentManager(), tabLayout.getTabCount());
      viewPager.setAdapter(adapter);
      viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
  
      tabLayout.setupWithViewPager(viewPager);
  
  
      return view;
  }
  </code></pre>
  
  <p>On android 5 and higher everything works just fine, and I can change between tabs using swipe, or by clicking on tab name. However, on lower android version, clicking on tabs doen't do anything, and the only way to change pages in ViewPager is by swiping. How can I make my TabLayout work on android including 4.1 and 4.4?</p>
  
  <p>Thanks for help!</p>