Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Tab Layout with many tabs

Tags:

android

tabs

I am creating an application which uses Tab Layout. The requirement of the app is that there should be many tabs. Making 4-5 tabs on the tab bar was ok. But when more tham 5 tabs are added, it gets very compressed. Is there a way in android where i can have many tabs and not make it look compressed? maybe some what like having a "More" button on the tab or having horizontal scrollable tabs?

I forgot to mention this earlier that it should work on android 2.2(api 8)

Thanks

like image 368
Gaurav Avatar asked Feb 13 '12 14:02

Gaurav


People also ask

How do I add multiple tabs on Android?

If you want to add Android tabs without sliding, then replace the layout with the fragment on tab selected listener event. And, if you want to add sliding tabs, then use ViewPager. In this Android tablayout example, we'll see how to create tabs in android studio with sliding using ViewPager.

How do you tabLayout on Android?

This example demonstrates how do I create a Tab Layout in android app. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 3 − Add the following code to res/layout/activity_main. xml.


1 Answers

For tab layout add the line

   app:tabMode="scrollable"

to your Xml file eg

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:tabMode="scrollable"
        app:tabTextColor="@color/colorWhite"
        app:tabSelectedTextColor="@color/colorSecondary"
        android:background="@color/colorPrimary"
        app:tabIndicatorColor="@color/colorSecondary"
        app:tabIndicatorHeight="5dp"/>
</android.support.design.widget.AppBarLayout>
like image 133
Clasence Avatar answered Sep 23 '22 05:09

Clasence