Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to hide tab from TabLayout

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;

}
like image 314
Tolyas Avatar asked Oct 15 '15 10:10

Tolyas


2 Answers

Did you try this?

 tabLayout.setupWithViewPager(viewPager);
 tabLayout.removeTabAt(0);
like image 77
Amit Avatar answered Nov 20 '22 14:11

Amit


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

((ViewGroup) tabLayout.getChildAt(0)).getChildAt(desiredPosition).setVisibility(View.GONE);//hides the tab
like image 36
Jerry Abraham Avatar answered Nov 20 '22 13:11

Jerry Abraham