10

I need to hide first tab. First page should work but when user select it, it should be seems like on tabs is selected. How I can do this?

I found some solutions with TabHost and it useless to me.

public class TabFragmentClients extends Fragment {

public static TabLayout tabLayout;
public static ViewPager viewPager;
public static int int_items = 5 ;
FinanceClients FinanceClients;

public ClientsFragment clientsFragment;
public FinanceFragment financeFragment;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    /**
     *Inflate tab_layout and setup Views.
     */
    final View x =  inflater.inflate(R.layout.tab_layout_clients,null);
    tabLayout = (TabLayout) x.findViewById(R.id.tabs);
    viewPager = (ViewPager) x.findViewById(R.id.viewpager);

    /**
     *Set an Apater for the View Pager
     */
    viewPager.setAdapter(new MyAdapter(getChildFragmentManager()));

    /**
     * Now , this is a workaround ,
     * The setupWithViewPager dose't works without the runnable .
     * Maybe a Support Library Bug .
     */
    tabLayout.post(new Runnable() {
        @Override
        public void run() {
            tabLayout.setupWithViewPager(viewPager);
        }
    });
    return x;

}
Tolyas
  • 442
  • 1
  • 6
  • 18
  • Could you explain more about your question? – Neo Oct 15 '15 at 10:14
  • 1
    There are actually 5 tabs. I need 4 of them visible and 1 hide. First tab should be like off the screen. – Tolyas Oct 15 '15 at 10:28
  • Check [this](http://stackoverflow.com/questions/5026653/how-to-hide-a-tab-in-android-tab-layout) solution. It uses tabHost, maybe you have used it wrong! – Caique Matos Mar 30 '17 at 12:55

2 Answers2

6
tabLayout = (TabLayout) findViewById(R.id.tabs);

((ViewGroup) tabLayout.getChildAt(0)).getChildAt(desiredPosition).setVisibility(View.GONE);//hides the tab
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Jerry Abraham
  • 1,039
  • 18
  • 42
4

Did you try this?

 tabLayout.setupWithViewPager(viewPager);
 tabLayout.removeTabAt(0);
Amit
  • 3,422
  • 3
  • 28
  • 39
  • This code is for remove not for the hide.But if you removed the tab than you can simply add again for this code " mTabLayout.addTab(mTabLayout.newTab().setText(title)); " – Dorbagna Feb 12 '19 at 12:17