San
San

Reputation: 2088

Adding a text ON the tab line in Tab Layout

I have been developing a project that requires the usage of swipe-able tab along with a notification text for each tab, the design goes like this. How do I achieve this ?

My thoughts :

I had an idea about adding a custom layout for the tab layout and adding two textviews below each other but it wont come over the tab line !!

Any ideas on how to achieve it ? A small hint would mean so much, thanks in advance.

CODE :

    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.addTab(tabLayout.newTab().setText("In Circle"));
    tabLayout.addTab(tabLayout.newTab().setText("You"));
    tabLayout.addTab(tabLayout.newTab().setText("Request"));

XML :

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/top_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <include
            android:id="@+id/bottom_item"
            layout="@layout/swipe_tab_header"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_above="@+id/tabs"
            android:layout_alignParentTop="true" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            style="@style/MyCustomTabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/viewpager"
            android:layout_marginBottom="5dp"
            app:tabGravity="fill"
            app:tabMaxWidth="0dp" />

        <RelativeLayout
            android:id="@+id/horizontal_slide_relative"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/tabs">

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/bottom_item"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />


            <include
                android:id="@+id/bottom_item"
                layout="@layout/tab_like_view_new"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_alignParentBottom="true" />

        </RelativeLayout>

    </android.support.design.widget.AppBarLayout>




</android.support.design.widget.CoordinatorLayout> 

Upvotes: 2

Views: 579

Answers (1)

Budius
Budius

Reputation: 39856

I guess the easiest way would be to have a LinearLayout on top of the TabLayout.

Something like following pseudo-xml, and you use the "margin_top" to properly adjust the numbers:

<FrameLayout>
   <android.support.design.widget.TabLayout height=48dp/>
   <LinearLayout margin_top=24dp>
      <TextView 
            layout_weight = 1
            background="circle"/> // add here your floating numbers
      <TextView 
            layout_weight = 1
            background="circle"/> // add here your floating numbers
      <TextView 
            layout_weight = 1
            background="circle"/> // add here your floating numbers
   </LinearLayout>
</FrameLayout>

Upvotes: 1

Related Questions