Android how to hide tab from TabLayout
Asked Answered
M

2

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;

}
Misbehave answered 15/10, 2015 at 10:7 Comment(3)
Could you explain more about your question?Xenophobe
There are actually 5 tabs. I need 4 of them visible and 1 hide. First tab should be like off the screen.Misbehave
Check this solution. It uses tabHost, maybe you have used it wrong!Jacques
E
6
tabLayout = (TabLayout) findViewById(R.id.tabs);

((ViewGroup) tabLayout.getChildAt(0)).getChildAt(desiredPosition).setVisibility(View.GONE);//hides the tab
Effortful answered 15/1, 2019 at 7:53 Comment(0)
P
4

Did you try this?

 tabLayout.setupWithViewPager(viewPager);
 tabLayout.removeTabAt(0);
Phonemics answered 14/7, 2016 at 9:5 Comment(1)
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)); "Gird

© 2022 - 2024 — McMap. All rights reserved.