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

This method is deprecated.
Use 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.

INDICATOR_GRAVITY_BOTTOM

int INDICATOR_GRAVITY_BOTTOM

Indicator gravity used to align the tab selection indicator to the bottom of the 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 setSelectedTabIndicatorHeight(int) (deprecated). Otherwise, the
indicator will not be shown. This is the default value.

INDICATOR_GRAVITY_CENTER

int INDICATOR_GRAVITY_CENTER

Indicator gravity used to align the tab selection indicator to the center of the 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 setSelectedTabIndicatorHeight(int) (deprecated). Otherwise, the
indicator will not be shown.

INDICATOR_GRAVITY_STRETCH

int INDICATOR_GRAVITY_STRETCH

Indicator gravity used to stretch the tab selection indicator across the entire height and
width of the TabLayout. This will disregard tabIndicatorHeight and the
indicator drawable's intrinsic height, if set.

INDICATOR_GRAVITY_TOP

int INDICATOR_GRAVITY_TOP

Indicator gravity used to align the tab selection indicator to the top of the 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 setSelectedTabIndicatorHeight(int) (deprecated). Otherwise, the
indicator will not be shown.

MODE_AUTO

int MODE_AUTO

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.

MODE_FIXED

int MODE_FIXED

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.

MODE_SCROLLABLE

int 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.

setSelectedTabIndicator

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 setSelectedTabIndicatorColor(int) the selection indicator will be tinted that color.
Otherwise, it will use the colors specified in the drawable.

setSelectedTabIndicator

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 setSelectedTabIndicatorColor(int) the selection indicator
will be tinted that color. Otherwise, it will use the colors specified in the drawable.

setSelectedTabIndicatorGravity

void setSelectedTabIndicatorGravity (int indicatorGravity)

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

setSelectedTabIndicatorHeight

void setSelectedTabIndicatorHeight (int height)

Sets the tab indicator's height for the currently selected tab. This method is deprecated. If
possible, set the intrinsic height directly on a custom indicator drawable passed to setSelectedTabIndicator(Drawable).

setTabIndicatorFullWidth

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.

setTabMode

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

MODE_FIXED: Fixed tabs display all tabs concurrently and are best used with
content that benefits from quick pivots between tabs.

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 ViewPager.

setTabTextColors

setTabsFromPagerAdapter

void setTabsFromPagerAdapter (PagerAdapter adapter)

This method is deprecated.
Use 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.

Parameters

adapter

PagerAdapter

setUnboundedRipple

void setUnboundedRipple (boolean unboundedRipple)

Set whether this TabLayout will have an unbounded ripple effect or if ripple will be
bound to the tab item size.

setupWithViewPager

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

autoRefresh

boolean: whether this layout should refresh its contents if the given ViewPager's
content changes