Search code examples
androidandroid-fragmentsandroid-tablayout

Hide Tablayout in some Fragments


I would like to hide my Tablayout in some Fragments my app will show up. One solution would be setting the android:aylout_height attribute of the TabLayout to eiher "0dp" or "wrap_content". But how do I set the height to 0dp programmatically? Is that even possible with a TabLayout?


Solution

  • In the fragments that you want your TabLayout to not show...

    tabLayout.setVisibility(View.GONE);
    

    I would put the above part of your code in your fragment's onCreateView() method.

    Then, in fragments where you want it to show again:

    tabLayout.setVisibility(View.VISIBLE);