TabLayout.Tab

public class TabLayout.Tab


A tab in this layout. Instances can be created via newTab.

Summary

Constants

static final int

An invalid position for a tab.

Public constructors

Tab()

Public methods

BadgeDrawable

Returns an instance of BadgeDrawable associated with this tab, null if none was initialized.

CharSequence

Gets a brief description of this tab's content for use in accessibility support.

View

Returns the custom view used for this tab.

Drawable

Return the icon associated with this tab.

int

Returns the id for this tab, View.NO_ID if not set.

BadgeDrawable

Creates an instance of BadgeDrawable if none exists.

int

Return the current position of this tab in the tab layout.

int

Gets the visibility mode for the Labels in this Tab.

Object
CharSequence

Return the text of this tab.

boolean

Returns true if this tab is currently selected.

void

Removes the BadgeDrawable.

void

Select this tab.

TabLayout.Tab

Set a description of this tab's content for use in accessibility support.

TabLayout.Tab

Set a description of this tab's content for use in accessibility support.

TabLayout.Tab
setCustomView(int resId)

Set a custom view to be used for this tab.

TabLayout.Tab
setCustomView(View view)

Set a custom view to be used for this tab.

TabLayout.Tab
setIcon(Drawable icon)

Set the icon displayed on this tab.

TabLayout.Tab
setIcon(int resId)

Set the icon displayed on this tab.

TabLayout.Tab
setId(int id)

Give this tab an id, useful for testing.

TabLayout.Tab

Sets the visibility mode for the Labels in this Tab.

TabLayout.Tab

Give this Tab an arbitrary object to hold for later use.

TabLayout.Tab
setText(int resId)

Set the text displayed on this tab.

TabLayout.Tab

Set the text displayed on this tab.

Constants

INVALID_POSITION

public static final int INVALID_POSITION = -1

An invalid position for a tab.

See also
getPosition

Public fields

customView

public View customView

icon

public Drawable icon

id

public int id

parent

public TabLayout parent

position

public int position

tag

public Object tag

text

public CharSequence text

view

public TabLayout.TabView view

Public constructors

Tab

public Tab()

Public methods

getBadge

public BadgeDrawable getBadge()

Returns an instance of BadgeDrawable associated with this tab, null if none was initialized.

getContentDescription

public CharSequence getContentDescription()

Gets a brief description of this tab's content for use in accessibility support.

Returns
CharSequence

Description of this tab's content

getCustomView

public View getCustomView()

Returns the custom view used for this tab.

getIcon

public Drawable getIcon()

Return the icon associated with this tab.

Returns
Drawable

The tab's icon

getId

public int getId()

Returns the id for this tab, View.NO_ID if not set.

getOrCreateBadge

public BadgeDrawable getOrCreateBadge()

Creates an instance of BadgeDrawable if none exists. Initializes (if needed) and returns the associated instance of BadgeDrawable.

Returns
BadgeDrawable

an instance of BadgeDrawable associated with Tab.

getPosition

public int getPosition()

Return the current position of this tab in the tab layout.

Returns
int

Current position, or INVALID_POSITION if this tab is not currently in the tab layout.

getTabLabelVisibility

public int getTabLabelVisibility()

Gets the visibility mode for the Labels in this Tab.

Returns
int

the label visibility mode, one of TAB_LABEL_VISIBILITY_UNLABELED or TAB_LABEL_VISIBILITY_LABELED.

getTag

public Object getTag()
Returns
Object

This Tab's tag object.

getText

public CharSequence getText()

Return the text of this tab.

Returns
CharSequence

The tab's text

isSelected

public boolean isSelected()

Returns true if this tab is currently selected.

removeBadge

public void removeBadge()

Removes the BadgeDrawable. Do nothing if none exists. Consider changing the visibility of the BadgeDrawable if you only want to hide it temporarily.

select

public void select()

Select this tab. Only valid if the tab has been added to the tab layout.

setContentDescription

public TabLayout.Tab setContentDescription(CharSequence contentDesc)

Set a description of this tab's content for use in accessibility support. If no content description is provided the title will be used.

Parameters
CharSequence contentDesc

Description of this tab's content

Returns
TabLayout.Tab

The current instance for call chaining

setContentDescription

public TabLayout.Tab setContentDescription(int resId)

Set a description of this tab's content for use in accessibility support. If no content description is provided the title will be used.

Parameters
int resId

A resource ID referring to the description text

Returns
TabLayout.Tab

The current instance for call chaining

setCustomView

public TabLayout.Tab setCustomView(int resId)

Set a custom view to be used for this tab.

If the inflated layout contains a TextView with an ID of text1 then that will be updated with the value given to setText. Similarly, if this layout contains an ImageView with ID icon then it will be updated with the value given to setIcon.

Parameters
int resId

A layout resource to inflate and use as a custom tab view

Returns
TabLayout.Tab

The current instance for call chaining

setCustomView

public TabLayout.Tab setCustomView(View view)

Set a custom view to be used for this tab.

If the provided view contains a TextView with an ID of text1 then that will be updated with the value given to setText. Similarly, if this layout contains an ImageView with ID icon then it will be updated with the value given to setIcon.

Parameters
View view

Custom view to be used as a tab.

Returns
TabLayout.Tab

The current instance for call chaining

setIcon

public TabLayout.Tab setIcon(Drawable icon)

Set the icon displayed on this tab.

Parameters
Drawable icon

The drawable to use as an icon

Returns
TabLayout.Tab

The current instance for call chaining

setIcon

public TabLayout.Tab setIcon(int resId)

Set the icon displayed on this tab.

Parameters
int resId

A resource ID referring to the icon that should be displayed

Returns
TabLayout.Tab

The current instance for call chaining

setId

public TabLayout.Tab setId(int id)

Give this tab an id, useful for testing.

Do not rely on this if using setupWithViewPager

Parameters
int id

unique id for this tab

setTabLabelVisibility

public TabLayout.Tab setTabLabelVisibility(int mode)

Sets the visibility mode for the Labels in this Tab. The valid input options are:

Returns
TabLayout.Tab

The current instance for call chaining.

setTag

public TabLayout.Tab setTag(Object tag)

Give this Tab an arbitrary object to hold for later use.

Parameters
Object tag

Object to store

Returns
TabLayout.Tab

The current instance for call chaining

setText

public TabLayout.Tab setText(int resId)

Set the text displayed on this tab. Text may be truncated if there is not room to display the entire string.

Parameters
int resId

A resource ID referring to the text that should be displayed

Returns
TabLayout.Tab

The current instance for call chaining

setText

public TabLayout.Tab setText(CharSequence text)

Set the text displayed on this tab. Text may be truncated if there is not room to display the entire string.

Parameters
CharSequence text

The text to display

Returns
TabLayout.Tab

The current instance for call chaining