title: Set tab indicator position programatically in TabLayout support library
body: <p>In my application i am using TabLayout from support library with view pager.I have 3 fragments in it.Suppose i am in fragA which has a button which on clicked takes me to fragB.I am sucessfully going to fragB but only problem is that the tab indicator remains at fragA.</p>
  
  <p>Code</p>
  
  <pre><code> private void setupTablayout() {
  
  
          tabLayout = (TabLayout) findViewById(R.id.tabLayout);
          tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
          tabLayout.setupWithViewPager(viewPager);
          viewPager.setCurrentItem(1, true);
  
          tabLayout.getTabAt(0).setIcon(R.drawable.archive).setText("");
          tabLayout.getTabAt(1).setIcon(R.drawable.status_1).setText("");
          tabLayout.getTabAt(2).setIcon(R.drawable.settings).setText("");
  
          tvHeader.setText("STATUS");
  
          tabLayout.setOnTabSelectedListener(this);
          //tabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
  
  
      }
  
      @Override
      public void onTabSelected(TabLayout.Tab tab) {
  
          viewPager.setCurrentItem(tab.getPosition());
          switch (tab.getPosition()) {
              case 0:
  
                  tab.setIcon(R.drawable.archive_1).setText("");
                  tvHeader.setText("ARCHIVES");
                  tvDate.setVisibility(View.GONE);
                  ivRefresh.setVisibility(View.VISIBLE);
  
                  break;
              case 1:
                  tab.setIcon(R.drawable.status_1).setText("");
                  tvHeader.setText("STATUS");
                  tvDate.setVisibility(View.VISIBLE);
                  ivRefresh.setVisibility(View.VISIBLE);
                  break;
              case 2:
                  tab.setIcon(R.drawable.settings_1).setText("");
                  tvHeader.setText("SETTINGS");
                  tvDate.setVisibility(View.GONE);
                  ivRefresh.setVisibility(View.GONE);
                  break;
  
  
          }
      }
  
      @Override
      public void onTabUnselected(TabLayout.Tab tab) {
  
  
          viewPager.setCurrentItem(tab.getPosition());
          switch (tab.getPosition()) {
              case 0:
  
                  tab.setIcon(R.drawable.archive).setText("");
  
                  break;
              case 1:
                  tab.setIcon(R.drawable.status).setText("");
                  break;
              case 2:
                  tab.setIcon(R.drawable.settings).setText("");
                  break;
  
  
          }
  
      }
  
  
      @Override
      public void onTabReselected(TabLayout.Tab tab) {
  
          viewPager.setCurrentItem(tab.getPosition());
          switch (tab.getPosition()) {
              case 0:
  
                  tab.setIcon(R.drawable.archive).setText("");
  
                  break;
              case 1:
                  tab.setIcon(R.drawable.status).setText("");
  
                  break;
              case 2:
                  tab.setIcon(R.drawable.settings).setText("");
                  break;
  
  
          }
  
      }
  
      class MyPagerAdapter extends FragmentPagerAdapter {
  
  
          public MyPagerAdapter(FragmentManager manager) {
              super(manager);
          }
  
          @Override
          public Fragment getItem(int position) {
  
              Fragment fragment = null;
  
              switch (position) {
                  case 0:
  
  //                    tabLayout.getTabAt(0).setIcon(R.drawable.archive_1).setText("");
  //                    tabLayout.getTabAt(1).setIcon(R.drawable.status).setText("");
  //                    tabLayout.getTabAt(2).setIcon(R.drawable.settings).setText("");
                      fragment = new ArchivesFrag();
  
  
                      break;
                  case 1:
  //                    tabLayout.getTabAt(0).setIcon(R.drawable.archive).setText("");
  //                    tabLayout.getTabAt(1).setIcon(R.drawable.status_1).setText("");
  //                    tabLayout.getTabAt(2).setIcon(R.drawable.settings).setText("");
                      fragment = StatusFrag.newInstance(listPosition);
  
                      break;
                  case 2:
  //                    tabLayout.getTabAt(0).setIcon(R.drawable.archive).setText("");
  //                    tabLayout.getTabAt(1).setIcon(R.drawable.status).setText("");
  //                    tabLayout.getTabAt(2).setIcon(R.drawable.settings_1).setText("");
                      fragment = new SettingFrag();
  
                      break;
  
  
              }
              return fragment;
          }
  
          @Override
          public int getCount() {
              return 3;
          }
  
  
      }
  </code></pre>
  
  <p>FragA </p>
  
  <pre><code>{
  
          ((Home) getActivity()).getArchiveList();
      }
  </code></pre>