0
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            app:tabMode="scrollable">

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab1" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab2" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab3" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab4" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab5" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab6" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab7" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab8" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab9" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab10" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab11" />

            <com.google.android.material.tabs.TabItem
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Tab12" />
        </com.google.android.material.tabs.TabLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".TabActivity" />
    </androidx.core.widget.NestedScrollView>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

I earlier asked on question on TabHost from that duplicate I notice in an answer that TabHost isn't deperecated. TabLayout is deprecated. Would it be better if I use TabLayout? If not than what I should use what is the alternative of TabLayout? Here is the TabLayout. In this question AskNilesh is saying to use com.google.android.material.tabs.TabLayout. But, we use it for TabLayout. I tried to create Tabbed Activity enter image description here

It is also containing TabLayout.

1 Answers1

0

it would be better to use TabLayout just because TabHost is in fact deprecated (and TabLayout isn't). check out doc, not SO questions...

This class was deprecated in API level 30. new applications should use fragment APIs instead of this class: Use TabLayout and ViewPager instead.

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • But, my question is how to get scrollable? In `TabWidget` I am unable to set `scrollable`/`tabMode`. I want `tab` like play store –  Feb 01 '21 at 07:04
  • well, no, you have two questions in your post: `Would it be better if I use TabLayout? If not than what I should use what is the alternative of TabLayout?` and not a single `scollable` word – snachmsm Feb 01 '21 at 07:05
  • So, what would you suggest for scrollable? –  Feb 01 '21 at 07:06
  • 1
    I don't know, I'm not familiar so close to scollable feature of `TabHost`/`TabLayout`, sorry... – snachmsm Feb 01 '21 at 07:08