# TabLayout

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/tabs/TabLayout.java)

*** ** * ** ***


```
public class TabLayout
```

<br />

*** ** * ** ***

TabLayout provides a horizontal layout to display tabs.

Population of the tabs to display is done through `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` instances. You create tabs via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#newTab()`. From there you can change the tab's label or icon via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setText(int)` and `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setIcon(int)` respectively. To display the tab, you need to add it to the layout via one of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addTab(com.google.android.material.tabs.TabLayout.Tab)` methods. For example:

```
TabLayout tabLayout = ...;
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
```
You should add a listener via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)` to be notified when any tab's selection state has been changed.

You can also add items to TabLayout in your layout through the use of `https://developer.android.com/reference/com/google/android/material/tabs/TabItem`. An example usage is like so:

```
<com.google.android.material.tabs.TabLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent">

    <com.google.android.material.tabs.TabItem
            android:text="@string/tab_text"/>

    <com.google.android.material.tabs.TabItem
            android:icon="@drawable/ic_android"/>

</com.google.android.material.tabs.TabLayout>
```

### ViewPager integration

If you're using a androidx.viewpager.widget.ViewPager together with this layout, you can call `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setupWithViewPager(ViewPager)` to link the two together. This layout will be automatically populated from the PagerAdapter's page titles.

This view also supports being used as part of a ViewPager's decor, and can be added directly to the ViewPager in a layout resource file like so:

```
<androidx.viewpager.widget.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.tabs.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top" />

</androidx.viewpager.widget.ViewPager>
```

For more information, see the [component developer guidance](https://github.com/material-components/material-components-android/blob/master/docs/components/Tabs.md) and [design guidelines](https://material.io/components/tabs/overview).

ref com.google.android.material.R.styleable#TabLayout_tabPadding

ref com.google.android.material.R.styleable#TabLayout_tabPaddingStart

ref com.google.android.material.R.styleable#TabLayout_tabPaddingTop

ref com.google.android.material.R.styleable#TabLayout_tabPaddingEnd

ref com.google.android.material.R.styleable#TabLayout_tabPaddingBottom

ref com.google.android.material.R.styleable#TabLayout_tabContentStart

ref com.google.android.material.R.styleable#TabLayout_tabBackground

ref com.google.android.material.R.styleable#TabLayout_tabMinWidth

ref com.google.android.material.R.styleable#TabLayout_tabMaxWidth

ref com.google.android.material.R.styleable#TabLayout_tabTextAppearance

| See also |
|---|---|
| `http://www.google.com/design/spec/components/tabs.html` | [Tabs](http://www.google.com/design/spec/components/tabs.html) |

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.BaseOnTabSelectedListener<T extends https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab>` **This interface is deprecated.** Use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener` instead. <br /> |
| `public interface https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener extends https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.BaseOnTabSelectedListener` Callback interface invoked when a tab's selection state changes. |
| `public class https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` A tab in this layout. |
| `public class https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.TabLayoutOnPageChangeListener` A ViewPager.OnPageChangeListener class which contains the necessary calls back to the provided `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` so that the tab position is kept in sync. |
| `public final inner class https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.TabView` A LinearLayout containing `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` instances for use with `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `public class https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.ViewPagerOnTabSelectedListener implements https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener` A `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener` class which contains the necessary calls back to the provided ViewPager so that the tab position is kept in sync. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#GRAVITY_CENTER() = 1` Gravity used to lay out the tabs in the center of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#GRAVITY_FILL() = 0` Gravity used to fill the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` as much as possible. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#GRAVITY_START() = 2` Gravity used to lay out the tabs aligned to the start of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_ANIMATION_MODE_ELASTIC() = 1` Indicator animation mode used to translate the selected tab indicator by growing and then shrinking the indicator, making the indicator look like it is stretching while translating between destinations. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_ANIMATION_MODE_FADE() = 2` Indicator animation mode used to switch the selected tab indicator from one tab to another by sequentially fading it out from the current destination and in at its new destination. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_ANIMATION_MODE_LINEAR() = 0` Indicator animation mode used to translate the selected tab indicator between two tabs using a linear motion. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_BOTTOM() = 0` Indicator gravity used to align the tab selection indicator to the bottom of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_CENTER() = 1` Indicator gravity used to align the tab selection indicator to the center of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_STRETCH() = 3` Indicator gravity used to stretch the tab selection indicator across the entire height of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_TOP() = 2` Indicator gravity used to align the tab selection indicator to the top of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#MODE_AUTO() = 2` Auto-sizing tabs behave like MODE_FIXED with GRAVITY_CENTER while the tabs fit within the TabLayout's content width. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#MODE_FIXED() = 1` Fixed tabs display all tabs concurrently and are best used with content that benefits from quick pivots between tabs. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#MODE_SCROLLABLE() = 0` Scrollable tabs display a subset of tabs at any given moment, and can contain longer tab labels and a larger number of tabs. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#TAB_LABEL_VISIBILITY_LABELED() = 1` This mode is set by default. |
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#TAB_LABEL_VISIBILITY_UNLABELED() = 0` If a tab is instantiated with `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setText(java.lang.CharSequence)`, and this mode is set, the text will be saved and utilized for the content description, but no visible labels will be created. |

| ### Public fields |
|---|---|
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#tabGravity()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#tabIconTint()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#tabIndicatorAnimationMode()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#tabIndicatorGravity()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#tabSelectedIndicator()` |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#tabTextColors()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#TabLayout(Context)(Context context)` |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#TabLayout(Context,AttributeSet)(Context context, AttributeSet attrs)` |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#TabLayout(Context,AttributeSet,int)(Context context, AttributeSet attrs, int defStyleAttr)` |

| ### Public methods |
|---|---|
| `void` | `[addOnTabSelectedListener](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener))(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.BaseOnTabSelectedListener listener)` **This method is deprecated.** use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)` <br /> |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener listener)` Add a `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener` that will be invoked when tab selection changes. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addTab(com.google.android.material.tabs.TabLayout.Tab)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab)` Add a tab to this layout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addTab(com.google.android.material.tabs.TabLayout.Tab,int)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab, int position)` Add a tab to this layout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addTab(com.google.android.material.tabs.TabLayout.Tab,boolean)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab, boolean setSelected)` Add a tab to this layout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addTab(com.google.android.material.tabs.TabLayout.Tab,int,boolean)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab, int position, boolean setSelected)` Add a tab to this layout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addView(View)(View child)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addView(View,int)(View child, int index)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addView(View,ViewGroup.LayoutParams)(View child, LayoutParams params)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addView(View,int,ViewGroup.LayoutParams)(View child, int index, LayoutParams params)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#clearOnTabSelectedListeners()()` Remove all previously added `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener`s. |
| `LayoutParams` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#generateLayoutParams(AttributeSet)(AttributeSet attrs)` |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getSelectedTabPosition()()` Returns the position of the current selected tab. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabAt(int)(int index)` Returns the tab at the specified index. |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabCount()()` Returns the number of tabs currently registered with the tab layout. |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabGravity()()` The current gravity used for laying out tabs. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIconTint()()` Gets the icon tint for the different states (normal, selected) used for the tabs. |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorAnimationMode()()` Get the current indicator animation mode used to animate the selection indicator between destinations. |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorGravity()()` Get the current indicator gravity used to align the tab selection indicator in the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabMode()()` Returns the current mode used by this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabRippleColor()()` Returns the ripple color for this TabLayout. |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabSelectedIndicator()()` Returns the selection indicator drawable for this TabLayout. |
| `ColorStateList` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabTextColors()()` Gets the text colors for the different states (normal, selected) used for the tabs. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#hasUnboundedRipple()()` Returns whether this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` has an unbounded ripple effect, or if ripple is bound to the tab item size. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#isInlineLabel()()` Returns whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#isTabIndicatorFullWidth()()` Get whether or not selection indicator width is fit to full width of the tab item, or fit to the tab item's content. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#newTab()()` Create and return a new `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab`. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo)(AccessibilityNodeInfo info)` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#onInterceptTouchEvent(MotionEvent)(MotionEvent event)` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#onTouchEvent(MotionEvent)(MotionEvent event)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeAllTabs()()` Remove all tabs from the tab layout and deselect the current tab. |
| `void` | `[removeOnTabSelectedListener](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener))( https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.BaseOnTabSelectedListener listener )` **This method is deprecated.** use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)` <br /> |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener listener)` Remove the given `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener` that was previously added via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)`. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeTab(com.google.android.material.tabs.TabLayout.Tab)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab)` Remove a tab from the layout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeTabAt(int)(int position)` Remove a tab from the layout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#selectTab(com.google.android.material.tabs.TabLayout.Tab)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab)` Selects the given tab. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#selectTab(com.google.android.material.tabs.TabLayout.Tab,boolean)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab, boolean updateIndicator)` Selects the given tab. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setElevation(float)(float elevation)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setInlineLabel(boolean)(boolean inline)` Set whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setInlineLabelResource(int)(int inlineResourceId)` Set whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons. |
| `void` | `[setOnTabSelectedListener](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setOnTabSelectedListener(com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener))(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.BaseOnTabSelectedListener listener)` **This method is deprecated.** Use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)` and `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)`. <br /> |
| `void` | `[setOnTabSelectedListener](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener))(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener listener)` **This method is deprecated.** Use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)` and `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)`. <br /> |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setScrollPosition(int,float,boolean)( int position, float positionOffset, boolean updateSelectedTabView )` Set the scroll position of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setScrollPosition(int,float,boolean,boolean)( int position, float positionOffset, boolean updateSelectedTabView, boolean updateIndicatorPosition )` Set the scroll position of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicator(Drawable)(Drawable tabSelectedIndicator)` Sets the selection indicator for this TabLayout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicator(int)(int tabSelectedIndicatorResourceId)` Sets the drawable resource to use as the selection indicator for this TabLayout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorColor(int)(int color)` Sets the tab indicator's color for the currently selected tab. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorGravity(int)(int indicatorGravity)` Set the indicator gravity used to align the tab selection indicator in the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. |
| `void` | `[setSelectedTabIndicatorHeight](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorHeight(int))(int height)` **This method is deprecated.** If possible, set the intrinsic height directly on a custom indicator drawable passed to `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicator(Drawable)`. <br /> |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabGravity(int)(int gravity)` Set the gravity to use when laying out the tabs. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabIconTint(ColorStateList)(ColorStateList iconTint)` Sets the icon tint for the different states (normal, selected) used for the tabs. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabIconTintResource(int)(int iconTintResourceId)` Sets the icon tint resource for the different states (normal, selected) used for the tabs. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabIndicatorAnimationMode(int)(int tabIndicatorAnimationMode)` Set the mode by which the selection indicator should animate when moving between destinations. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabIndicatorFullWidth(boolean)(boolean tabIndicatorFullWidth)` Enable or disable option to fit the tab selection indicator to the full width of the tab item rather than to the tab item's content. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabMode(int)(int mode)` Set the behavior mode for the Tabs in this layout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabRippleColor(ColorStateList)(ColorStateList color)` Sets the ripple color for this TabLayout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabRippleColorResource(int)(int tabRippleColorResourceId)` Sets the ripple color resource for this TabLayout. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabTextColors(ColorStateList)(ColorStateList textColor)` Sets the text colors for the different states (normal, selected) used for the tabs. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabTextColors(int,int)(int normalColor, int selectedColor)` Sets the text colors for the different states (normal, selected) used for the tabs. |
| `void` | `[setTabsFromPagerAdapter](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabsFromPagerAdapter(PagerAdapter))(PagerAdapter adapter)` **This method is deprecated.** Use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setupWithViewPager(ViewPager)` to link a TabLayout with a ViewPager together. <br /> |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setUnboundedRipple(boolean)(boolean unboundedRipple)` Set whether this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` will have an unbounded ripple effect or if ripple will be bound to the tab item size. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setUnboundedRippleResource(int)(int unboundedRippleResourceId)` Set whether this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` will have an unbounded ripple effect or if ripple will be bound to the tab item size. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setupWithViewPager(ViewPager)(ViewPager viewPager)` The one-stop shop for setting up this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` with a ViewPager. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setupWithViewPager(ViewPager,boolean)(ViewPager viewPager, boolean autoRefresh)` The one-stop shop for setting up this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` with a ViewPager. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#shouldDelayChildPressedState()()` |

| ### Protected methods |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#createTabFromPool()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#onAttachedToWindow()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#onDetachedFromWindow()()` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#onDraw(Canvas)(Canvas canvas)` |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#onMeasure(int,int)(int widthMeasureSpec, int heightMeasureSpec)` |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#releaseFromTabPool(com.google.android.material.tabs.TabLayout.Tab)(https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab)` |

## Constants

### GRAVITY_CENTER

```
public static final int GRAVITY_CENTER = 1
```

Gravity used to lay out the tabs in the center of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabGravity()` |   |

### GRAVITY_FILL

```
public static final int GRAVITY_FILL = 0
```

Gravity used to fill the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` as much as possible. This option only takes effect when used with `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#MODE_FIXED()` on non-landscape screens less than 600dp wide.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabGravity()` |   |

### GRAVITY_START

```
public static final int GRAVITY_START = 2
```

Gravity used to lay out the tabs aligned to the start of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabGravity()` |   |

### INDICATOR_ANIMATION_MODE_ELASTIC

```
public static final int INDICATOR_ANIMATION_MODE_ELASTIC = 1
```

Indicator animation mode used to translate the selected tab indicator by growing and then shrinking the indicator, making the indicator look like it is stretching while translating between destinations.

The left and right side of the selection indicator translate out of step - with the right decelerating and the left accelerating (when moving right). This difference in velocity between the sides of the indicator, over the duration of the animation, make the indicator look like it grows and then shrinks back down to fit it's new destination's width.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorAnimationMode

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabIndicatorAnimationMode(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorAnimationMode()` |   |

### INDICATOR_ANIMATION_MODE_FADE

```
public static final int INDICATOR_ANIMATION_MODE_FADE = 2
```

Indicator animation mode used to switch the selected tab indicator from one tab to another by sequentially fading it out from the current destination and in at its new destination.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorAnimationMode

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabIndicatorAnimationMode(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorAnimationMode()` |   |

### INDICATOR_ANIMATION_MODE_LINEAR

```
public static final int INDICATOR_ANIMATION_MODE_LINEAR = 0
```

Indicator animation mode used to translate the selected tab indicator between two tabs using a linear motion.

The left and right side of the selection indicator translate in step over the duration of the animation. The only exception to this is when the indicator needs to change size to fit the width of its new destination tab's label.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorAnimationMode

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabIndicatorAnimationMode(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorAnimationMode()` |   |

### INDICATOR_GRAVITY_BOTTOM

```
public static final int INDICATOR_GRAVITY_BOTTOM = 0
```

Indicator gravity used to align the tab selection indicator to the bottom of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. This will only take effect if the indicator height is set via the custom indicator drawable's intrinsic height (preferred), via the `tabIndicatorHeight` attribute (deprecated), or via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorHeight(int)` (deprecated). Otherwise, the indicator will not be shown. This is the default value.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorGravity

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorGravity()` |   |

### INDICATOR_GRAVITY_CENTER

```
public static final int INDICATOR_GRAVITY_CENTER = 1
```

Indicator gravity used to align the tab selection indicator to the center of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. This will only take effect if the indicator height is set via the custom indicator drawable's intrinsic height (preferred), via the `tabIndicatorHeight` attribute (deprecated), or via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorHeight(int)` (deprecated). Otherwise, the indicator will not be shown.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorGravity

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorGravity()` |   |

### INDICATOR_GRAVITY_STRETCH

```
public static final int INDICATOR_GRAVITY_STRETCH = 3
```

Indicator gravity used to stretch the tab selection indicator across the entire height of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. This will disregard `tabIndicatorHeight` and the indicator drawable's intrinsic height, if set.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorGravity

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorGravity()` |   |

### INDICATOR_GRAVITY_TOP

```
public static final int INDICATOR_GRAVITY_TOP = 2
```

Indicator gravity used to align the tab selection indicator to the top of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. This will only take effect if the indicator height is set via the custom indicator drawable's intrinsic height (preferred), via the `tabIndicatorHeight` attribute (deprecated), or via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorHeight(int)` (deprecated). Otherwise, the indicator will not be shown.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorGravity

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorGravity(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorGravity()` |   |

### MODE_AUTO

```
public static final int MODE_AUTO = 2
```

Auto-sizing tabs behave like MODE_FIXED with GRAVITY_CENTER while the tabs fit within the TabLayout's content width. Fixed tabs have equal width, based on the widest tab label. Once the tabs outgrow the view's width, auto-sizing tabs behave like MODE_SCROLLABLE, allowing for a dynamic number of tabs without requiring additional layout logic.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabMode(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabMode()` |   |

### MODE_FIXED

```
public static final int MODE_FIXED = 1
```

Fixed tabs display all tabs concurrently and are best used with content that benefits from quick pivots between tabs. The maximum number of tabs is limited by the view's width. Fixed tabs have equal width, based on the widest tab label.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabMode(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabMode()` |   |

### MODE_SCROLLABLE

```
public static final int MODE_SCROLLABLE = 0
```

Scrollable tabs display a subset of tabs at any given moment, and can contain longer tab labels and a larger number of tabs. They are best used for browsing contexts in touch interfaces when users don't need to directly compare the tab labels.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabMode(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabMode()` |   |

### TAB_LABEL_VISIBILITY_LABELED

```
public static final int TAB_LABEL_VISIBILITY_LABELED = 1
```

This mode is set by default. If a tab is instantiated with `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setText(java.lang.CharSequence)`, a visible label will be created.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setTabLabelVisibility(int)` |   |

### TAB_LABEL_VISIBILITY_UNLABELED

```
public static final int TAB_LABEL_VISIBILITY_UNLABELED = 0
```

If a tab is instantiated with `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setText(java.lang.CharSequence)`, and this mode is set, the text will be saved and utilized for the content description, but no visible labels will be created.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setTabLabelVisibility(int)` |   |

## Public fields

### tabGravity

```
public int tabGravity
```

### tabIconTint

```
public ColorStateList tabIconTint
```

### tabIndicatorAnimationMode

```
public int tabIndicatorAnimationMode
```

### tabIndicatorGravity

```
public int tabIndicatorGravity
```

### tabSelectedIndicator

```
public Drawable tabSelectedIndicator
```

### tabTextColors

```
public ColorStateList tabTextColors
```

## Public constructors

### TabLayout

```
public TabLayout(Context context)
```

### TabLayout

```
public TabLayout(Context context, AttributeSet attrs)
```

### TabLayout

```
public TabLayout(Context context, AttributeSet attrs, int defStyleAttr)
```

## Public methods

### addOnTabSelectedListener

```
public void [addOnTabSelectedListener](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener))(TabLayout.BaseOnTabSelectedListener listener)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)`

Add a `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.BaseOnTabSelectedListener` that will be invoked when tab selection changes.

Components that add a listener should take care to remove it when finished via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.BaseOnTabSelectedListener listener` | listener to add |

### addOnTabSelectedListener

```
public void addOnTabSelectedListener(TabLayout.OnTabSelectedListener listener)
```

Add a `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener` that will be invoked when tab selection changes.

Components that add a listener should take care to remove it when finished via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener listener` | listener to add |

### addTab

```
public void addTab(TabLayout.Tab tab)
```

Add a tab to this layout. The tab will be added at the end of the list. If this is the first tab to be added it will become the selected tab.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab` | Tab to add |

### addTab

```
public void addTab(TabLayout.Tab tab, int position)
```

Add a tab to this layout. The tab will be inserted at `position`. If this is the first tab to be added it will become the selected tab.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab` | The tab to add |
| `int position` | The new position of the tab |

### addTab

```
public void addTab(TabLayout.Tab tab, boolean setSelected)
```

Add a tab to this layout. The tab will be added at the end of the list.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab` | Tab to add |
| `boolean setSelected` | True if the added tab should become the selected tab. |

### addTab

```
public void addTab(TabLayout.Tab tab, int position, boolean setSelected)
```

Add a tab to this layout. The tab will be inserted at `position`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab` | The tab to add |
| `int position` | The new position of the tab |
| `boolean setSelected` | True if the added tab should become the selected tab. |

### addView

```
public void addView(View child)
```

### addView

```
public void addView(View child, int index)
```

### addView

```
public void addView(View child, LayoutParams params)
```

### addView

```
public void addView(View child, int index, LayoutParams params)
```

### clearOnTabSelectedListeners

```
public void clearOnTabSelectedListeners()
```

Remove all previously added `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener`s.

### generateLayoutParams

```
public LayoutParams generateLayoutParams(AttributeSet attrs)
```

### getSelectedTabPosition

```
public int getSelectedTabPosition()
```

Returns the position of the current selected tab.

| Returns |
|---|---|
| `int` | selected tab position, or `-1` if there isn't a selected tab. |

### getTabAt

```
public TabLayout.Tab getTabAt(int index)
```

Returns the tab at the specified index.

### getTabCount

```
public int getTabCount()
```

Returns the number of tabs currently registered with the tab layout.

| Returns |
|---|---|
| `int` | Tab count |

### getTabGravity

```
public int getTabGravity()
```

The current gravity used for laying out tabs.

| Returns |
|---|---|
| `int` | one of `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#GRAVITY_CENTER()` or `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#GRAVITY_FILL()`. |

### getTabIconTint

```
public ColorStateList getTabIconTint()
```

Gets the icon tint for the different states (normal, selected) used for the tabs.

### getTabIndicatorAnimationMode

```
public int getTabIndicatorAnimationMode()
```

Get the current indicator animation mode used to animate the selection indicator between destinations.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorAnimationMode

| Returns |
|---|---|
| `int` | one of `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_ANIMATION_MODE_LINEAR()` or `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_ANIMATION_MODE_ELASTIC()` |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabIndicatorAnimationMode(int)` |   |

### getTabIndicatorGravity

```
public int getTabIndicatorGravity()
```

Get the current indicator gravity used to align the tab selection indicator in the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`.

| Returns |
|---|---|
| `int` | one of `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_BOTTOM()`, `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_CENTER()`, `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_TOP()`, or `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_STRETCH()` |

### getTabMode

```
public int getTabMode()
```

Returns the current mode used by this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabMode(int)` |   |

### getTabRippleColor

```
public ColorStateList getTabRippleColor()
```

Returns the ripple color for this TabLayout.

| Returns |
|---|---|
| `ColorStateList` | the color (or ColorStateList) used for the ripple |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabRippleColor(ColorStateList)` |   |

### getTabSelectedIndicator

```
public Drawable getTabSelectedIndicator()
```

Returns the selection indicator drawable for this TabLayout.

| Returns |
|---|---|
| `Drawable` | The drawable used as the tab selection indicator, if set. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicator(Drawable)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicator(int)` |   |

### getTabTextColors

```
public ColorStateList getTabTextColors()
```

Gets the text colors for the different states (normal, selected) used for the tabs.

### hasUnboundedRipple

```
public boolean hasUnboundedRipple()
```

Returns whether this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` has an unbounded ripple effect, or if ripple is bound to the tab item size.

ref com.google.android.material.R.styleable#TabLayout_tabUnboundedRipple

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setUnboundedRipple(boolean)` |   |

### isInlineLabel

```
public boolean isInlineLabel()
```

Returns whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.

ref com.google.android.material.R.styleable#TabLayout_tabInlineLabel

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setInlineLabel(boolean)` |   |

### isTabIndicatorFullWidth

```
public boolean isTabIndicatorFullWidth()
```

Get whether or not selection indicator width is fit to full width of the tab item, or fit to the tab item's content.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorFullWidth

| Returns |
|---|---|
| `boolean` | whether or not selection indicator width is fit to the full width of the tab item |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabIndicatorFullWidth(boolean)` |   |

### newTab

```
public TabLayout.Tab newTab()
```

Create and return a new `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab`. You need to manually add this using `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addTab(com.google.android.material.tabs.TabLayout.Tab)` or a related method.

| Returns |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | A new Tab |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addTab(com.google.android.material.tabs.TabLayout.Tab)` |   |

### onInitializeAccessibilityNodeInfo

```
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
```

### onInterceptTouchEvent

```
public boolean onInterceptTouchEvent(MotionEvent event)
```

### onTouchEvent

```
public boolean onTouchEvent(MotionEvent event)
```

### removeAllTabs

```
public void removeAllTabs()
```

Remove all tabs from the tab layout and deselect the current tab.

### removeOnTabSelectedListener

```
public void [removeOnTabSelectedListener](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener))(
    TabLayout.BaseOnTabSelectedListener listener
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)`

Remove the given `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.BaseOnTabSelectedListener` that was previously added via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.BaseOnTabSelectedListener listener` | listener to remove |

### removeOnTabSelectedListener

```
public void removeOnTabSelectedListener(TabLayout.OnTabSelectedListener listener)
```

Remove the given `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener` that was previously added via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.OnTabSelectedListener listener` | listener to remove |

### removeTab

```
public void removeTab(TabLayout.Tab tab)
```

Remove a tab from the layout. If the removed tab was selected it will be deselected and another tab will be selected if present.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab` | The tab to remove |

### removeTabAt

```
public void removeTabAt(int position)
```

Remove a tab from the layout. If the removed tab was selected it will be deselected and another tab will be selected if present.

| Parameters |
|---|---|
| `int position` | Position of the tab to remove |

### selectTab

```
public void selectTab(TabLayout.Tab tab)
```

Selects the given tab.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab` | The tab to select, or `null` to select none. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#selectTab(com.google.android.material.tabs.TabLayout.Tab,boolean)` |   |

### selectTab

```
public void selectTab(TabLayout.Tab tab, boolean updateIndicator)
```

Selects the given tab. Will always animate to the selected tab if the current tab is reselected, regardless of the value of `updateIndicator`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab tab` | The tab to select, or `null` to select none. |
| `boolean updateIndicator` | Whether to update the indicator. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#selectTab(com.google.android.material.tabs.TabLayout.Tab)` |   |

### setElevation

```
public void setElevation(float elevation)
```

### setInlineLabel

```
public void setInlineLabel(boolean inline)
```

Set whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.

ref com.google.android.material.R.styleable#TabLayout_tabInlineLabel

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#isInlineLabel()` |   |

### setInlineLabelResource

```
public void setInlineLabelResource(int inlineResourceId)
```

Set whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.

ref com.google.android.material.R.styleable#TabLayout_tabInlineLabel

| Parameters |
|---|---|
| `int inlineResourceId` | Resource ID for boolean inline flag |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#isInlineLabel()` |   |

### setOnTabSelectedListener

```
public void [setOnTabSelectedListener](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setOnTabSelectedListener(com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener))(TabLayout.BaseOnTabSelectedListener listener)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)` and `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)`.

### setOnTabSelectedListener

```
public void [setOnTabSelectedListener](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener))(TabLayout.OnTabSelectedListener listener)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#addOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)` and `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#removeOnTabSelectedListener(com.google.android.material.tabs.TabLayout.OnTabSelectedListener)`.

### setScrollPosition

```
public void setScrollPosition(
    int position,
    float positionOffset,
    boolean updateSelectedTabView
)
```

Set the scroll position of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`.

| Parameters |
|---|---|
| `int position` | Position of the tab to scroll. |
| `float positionOffset` | Value from \[0, 1) indicating the offset from `position`. |
| `boolean updateSelectedTabView` | Whether to draw the tab at the specified position + positionOffset as selected. Note that calling the method with `updateSelectedTabView = true`*does not* select a tab at the specified position, but only *draws it as selected*. This can be useful for when the TabLayout behavior needs to be linked to another view, such as androidx.viewpager.widget.ViewPager. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setScrollPosition(int,float,boolean,boolean)` |   |

### setScrollPosition

```
public void setScrollPosition(
    int position,
    float positionOffset,
    boolean updateSelectedTabView,
    boolean updateIndicatorPosition
)
```

Set the scroll position of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`.

| Parameters |
|---|---|
| `int position` | Position of the tab to scroll. |
| `float positionOffset` | Value from \[0, 1) indicating the offset from `position`. |
| `boolean updateSelectedTabView` | Whether to draw the tab at the specified position + positionOffset as selected. Note that calling the method with `updateSelectedTabView = true`*does not* select a tab at the specified position, but only *draws it as selected*. This can be useful for when the TabLayout behavior needs to be linked to another view, such as androidx.viewpager.widget.ViewPager. |
| `boolean updateIndicatorPosition` | Whether to set the indicator to the specified position and offset. Note that calling the method with `updateIndicatorPosition = true`*does not* select a tab at the specified position, but only updates the indicator position. This can be useful for when the TabLayout behavior needs to be linked to another view, such as androidx.viewpager.widget.ViewPager. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setScrollPosition(int,float,boolean)` |   |

### setSelectedTabIndicator

```
public void setSelectedTabIndicator(Drawable tabSelectedIndicator)
```

Sets the selection indicator for this TabLayout. By default, this is a line along the bottom of the tab. If `tabIndicatorColor` is specified via the TabLayout's style or via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorColor(int)` the selection indicator will be tinted that color. Otherwise, it will use the colors specified in the drawable.

Setting the indicator drawable to null will cause `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` to use the default, GradientDrawable line indicator.

| Parameters |
|---|---|
| `Drawable tabSelectedIndicator` | A drawable to use as the selected tab indicator. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorColor(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicator(int)` |   |

### setSelectedTabIndicator

```
public void setSelectedTabIndicator(int tabSelectedIndicatorResourceId)
```

Sets the drawable resource to use as the selection indicator for this TabLayout. By default, this is a line along the bottom of the tab. If `tabIndicatorColor` is specified via the TabLayout's style or via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorColor(int)` the selection indicator will be tinted that color. Otherwise, it will use the colors specified in the drawable.

| Parameters |
|---|---|
| `int tabSelectedIndicatorResourceId` | A drawable resource to use as the selected tab indicator. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorColor(int)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicator(Drawable)` |   |

### setSelectedTabIndicatorColor

```
public void setSelectedTabIndicatorColor(int color)
```

Sets the tab indicator's color for the currently selected tab.

If the tab indicator color is not `Color.TRANSPARENT`, the indicator will be wrapped and tinted right before it is drawn by `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.SlidingTabIndicator#draw(Canvas)`. If you'd like the inherent color or the tinted color of a custom drawable to be used, make sure this color is set to `Color.TRANSPARENT` to avoid your color/tint being overridden.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorColor

| Parameters |
|---|---|
| `int color` | color to use for the indicator |

### setSelectedTabIndicatorGravity

```
public void setSelectedTabIndicatorGravity(int indicatorGravity)
```

Set the indicator gravity used to align the tab selection indicator in the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. You must set the indicator height via the custom indicator drawable's intrinsic height (preferred), via the `tabIndicatorHeight` attribute (deprecated), or via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorHeight(int)` (deprecated). Otherwise, the indicator will not be shown unless gravity is set to `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_STRETCH()`, in which case it will ignore indicator height and stretch across the entire height of the `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout`. This defaults to `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_BOTTOM()` if not set.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorGravity

| Parameters |
|---|---|
| `int indicatorGravity` | one of `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_BOTTOM()`, `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_CENTER()`, `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_TOP()`, or `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_GRAVITY_STRETCH()` |

### setSelectedTabIndicatorHeight

```
public void [setSelectedTabIndicatorHeight](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicatorHeight(int))(int height)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> If possible, set the intrinsic height directly on a custom indicator drawable passed to `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setSelectedTabIndicator(Drawable)`.

Sets the tab indicator's height for the currently selected tab.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorHeight

| Parameters |
|---|---|
| `int height` | height to use for the indicator in pixels |

### setTabGravity

```
public void setTabGravity(int gravity)
```

Set the gravity to use when laying out the tabs.

ref com.google.android.material.R.styleable#TabLayout_tabGravity

| Parameters |
|---|---|
| `int gravity` | one of `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#GRAVITY_CENTER()` or `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#GRAVITY_FILL()`. |

### setTabIconTint

```
public void setTabIconTint(ColorStateList iconTint)
```

Sets the icon tint for the different states (normal, selected) used for the tabs.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIconTint()` |   |

### setTabIconTintResource

```
public void setTabIconTintResource(int iconTintResourceId)
```

Sets the icon tint resource for the different states (normal, selected) used for the tabs.

| Parameters |
|---|---|
| `int iconTintResourceId` | A color resource to use as icon tint. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIconTint()` |   |

### setTabIndicatorAnimationMode

```
public void setTabIndicatorAnimationMode(int tabIndicatorAnimationMode)
```

Set the mode by which the selection indicator should animate when moving between destinations.

Defaults to `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_ANIMATION_MODE_LINEAR()`. Changing this is useful as a stylistic choice.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorAnimationMode

| Parameters |
|---|---|
| `int tabIndicatorAnimationMode` | one of `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_ANIMATION_MODE_LINEAR()` or `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#INDICATOR_ANIMATION_MODE_ELASTIC()` |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabIndicatorAnimationMode()` |   |

### setTabIndicatorFullWidth

```
public void setTabIndicatorFullWidth(boolean tabIndicatorFullWidth)
```

Enable or disable option to fit the tab selection indicator to the full width of the tab item rather than to the tab item's content.

Defaults to true. If set to false and the tab item has a text label, the selection indicator width will be set to the width of the text label. If the tab item has no text label, but does have an icon, the selection indicator width will be set to the icon. If the tab item has neither of these, or if the calculated width is less than a minimum width value, the selection indicator width will be set to the minimum width value.

ref com.google.android.material.R.styleable#TabLayout_tabIndicatorFullWidth

| Parameters |
|---|---|
| `boolean tabIndicatorFullWidth` | Whether or not to fit selection indicator width to full width of the tab item |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#isTabIndicatorFullWidth()` |   |

### setTabMode

```
public void setTabMode(int mode)
```

Set the behavior mode for the Tabs in this layout. The valid input options are:

- `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#MODE_FIXED()`: Fixed tabs display all tabs concurrently and are best used with content that benefits from quick pivots between tabs.
- `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#MODE_SCROLLABLE()`: Scrollable tabs display a subset of tabs at any given moment, and can contain longer tab labels and a larger number of tabs. They are best used for browsing contexts in touch interfaces when users don't need to directly compare the tab labels. This mode is commonly used with a androidx.viewpager.widget.ViewPager.

ref com.google.android.material.R.styleable#TabLayout_tabMode

| Parameters |
|---|---|
| `int mode` | one of `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#MODE_FIXED()` or `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#MODE_SCROLLABLE()`. |

### setTabRippleColor

```
public void setTabRippleColor(ColorStateList color)
```

Sets the ripple color for this TabLayout.

When running on devices with KitKat, we draw this color as a filled overlay rather than a ripple.

ref com.google.android.material.R.styleable#TabLayout_tabRippleColor

| Parameters |
|---|---|
| `ColorStateList color` | color (or ColorStateList) to use for the ripple |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabRippleColor()` |   |

### setTabRippleColorResource

```
public void setTabRippleColorResource(int tabRippleColorResourceId)
```

Sets the ripple color resource for this TabLayout.

When running on devices with KitKat, we draw this color as a filled overlay rather than a ripple.

| Parameters |
|---|---|
| `int tabRippleColorResourceId` | A color resource to use as ripple color. |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabRippleColor()` |   |

### setTabTextColors

```
public void setTabTextColors(ColorStateList textColor)
```

Sets the text colors for the different states (normal, selected) used for the tabs.

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#getTabTextColors()` |   |

### setTabTextColors

```
public void setTabTextColors(int normalColor, int selectedColor)
```

Sets the text colors for the different states (normal, selected) used for the tabs.

ref com.google.android.material.R.styleable#TabLayout_tabTextColor

ref com.google.android.material.R.styleable#TabLayout_tabSelectedTextColor

### setTabsFromPagerAdapter

```
public void [setTabsFromPagerAdapter](https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setTabsFromPagerAdapter(PagerAdapter))(PagerAdapter adapter)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setupWithViewPager(ViewPager)` to link a TabLayout with a ViewPager together. When that method is used, the TabLayout will be automatically updated when the PagerAdapter is changed.

### setUnboundedRipple

```
public void setUnboundedRipple(boolean unboundedRipple)
```

Set whether this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` will have an unbounded ripple effect or if ripple will be bound to the tab item size.

Defaults to false.

ref com.google.android.material.R.styleable#TabLayout_tabUnboundedRipple

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#hasUnboundedRipple()` |   |

### setUnboundedRippleResource

```
public void setUnboundedRippleResource(int unboundedRippleResourceId)
```

Set whether this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` will have an unbounded ripple effect or if ripple will be bound to the tab item size. Defaults to false.

ref com.google.android.material.R.styleable#TabLayout_tabUnboundedRipple

| Parameters |
|---|---|
| `int unboundedRippleResourceId` | Resource ID for boolean unbounded ripple value |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#hasUnboundedRipple()` |   |

### setupWithViewPager

```
public void setupWithViewPager(ViewPager viewPager)
```

The one-stop shop for setting up this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` with a ViewPager.

This is the same as calling `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setupWithViewPager(ViewPager,boolean)` with auto-refresh enabled.

| Parameters |
|---|---|
| `ViewPager viewPager` | the ViewPager to link to, or `null` to clear any previous link |

### setupWithViewPager

```
public void setupWithViewPager(ViewPager viewPager, boolean autoRefresh)
```

The one-stop shop for setting up this `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` with a ViewPager.

This method will link the given ViewPager and this TabLayout together so that changes in one are automatically reflected in the other. This includes scroll state changes and clicks. The tabs displayed in this layout will be populated from the ViewPager adapter's page titles.

If `autoRefresh` is `true`, any changes in the PagerAdapter will trigger this layout to re-populate itself from the adapter's titles.

If the given ViewPager is non-null, it needs to already have a PagerAdapter set.

| Parameters |
|---|---|
| `ViewPager viewPager` | the ViewPager to link to, or `null` to clear any previous link |
| `boolean autoRefresh` | whether this layout should refresh its contents if the given ViewPager's content changes |

### shouldDelayChildPressedState

```
public boolean shouldDelayChildPressedState()
```

## Protected methods

### createTabFromPool

```
protected TabLayout.Tab createTabFromPool()
```

### onAttachedToWindow

```
protected void onAttachedToWindow()
```

### onDetachedFromWindow

```
protected void onDetachedFromWindow()
```

### onDraw

```
protected void onDraw(Canvas canvas)
```

### onMeasure

```
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
```

### releaseFromTabPool

```
protected boolean releaseFromTabPool(TabLayout.Tab tab)
```