Android APIs
public static final class

TabLayout.Tab

extends Object
java.lang.Object
   ↳ android.support.design.widget.TabLayout.Tab

Class Overview

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

Summary

Constants
int INVALID_POSITION An invalid position for a tab.
Public Methods
CharSequence getContentDescription()
Gets a brief description of this tab's content for use in accessibility support.
View getCustomView()
Returns the custom view used for this tab.
Drawable getIcon()
Return the icon associated with this tab.
int getPosition()
Return the current position of this tab in the action bar.
Object getTag()
CharSequence getText()
Return the text of this tab.
boolean isSelected()
Returns true if this tab is currently selected.
void select()
Select this tab.
TabLayout.Tab setContentDescription(int resId)
Set a description of this tab's content for use in accessibility support.
TabLayout.Tab setContentDescription(CharSequence contentDesc)
Set a description of this tab's content for use in accessibility support.
TabLayout.Tab setCustomView(int layoutResId)
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 setTag(Object tag)
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 setText(CharSequence text)
Set the text displayed on this tab.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int INVALID_POSITION

An invalid position for a tab.

See Also
Constant Value: -1 (0xffffffff)

Public Methods

public CharSequence getContentDescription ()

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

Returns
  • Description of this tab's content

public View getCustomView ()

Returns the custom view used for this tab.

public Drawable getIcon ()

Return the icon associated with this tab.

Returns
  • The tab's icon

public int getPosition ()

Return the current position of this tab in the action bar.

Returns
  • Current position, or INVALID_POSITION if this tab is not currently in the action bar.

public Object getTag ()

Returns
  • This Tab's tag object.

public CharSequence getText ()

Return the text of this tab.

Returns
  • The tab's text

public boolean isSelected ()

Returns true if this tab is currently selected.

public void select ()

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

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
resId A resource ID referring to the description text
Returns
  • The current instance for call chaining

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
contentDesc Description of this tab's content
Returns
  • The current instance for call chaining

public TabLayout.Tab setCustomView (int layoutResId)

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(CharSequence). Similarly, if this layout contains an ImageView with ID icon then it will be updated with the value given to setIcon(Drawable).

Parameters
layoutResId A layout resource to inflate and use as a custom tab view
Returns
  • The current instance for call chaining

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(CharSequence). Similarly, if this layout contains an ImageView with ID icon then it will be updated with the value given to setIcon(Drawable).

Parameters
view Custom view to be used as a tab.
Returns
  • The current instance for call chaining

public TabLayout.Tab setIcon (Drawable icon)

Set the icon displayed on this tab.

Parameters
icon The drawable to use as an icon
Returns
  • The current instance for call chaining

public TabLayout.Tab setIcon (int resId)

Set the icon displayed on this tab.

Parameters
resId A resource ID referring to the icon that should be displayed
Returns
  • The current instance for call chaining

public TabLayout.Tab setTag (Object tag)

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

Parameters
tag Object to store
Returns
  • The current instance for call chaining

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
resId A resource ID referring to the text that should be displayed
Returns
  • The current instance for call chaining

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
text The text to display
Returns
  • The current instance for call chaining