# TabLayout.Tab

[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.Tab
```

<br />

*** ** * ** ***

A tab in this layout. Instances can be created via `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#newTab()`.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#INVALID_POSITION() = -1` An invalid position for a tab. |

| ### Public fields |
|---|---|
| `View` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#customView()` |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#icon()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#id()` |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#parent()` |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#position()` |
| `https://developer.android.com/reference/java/lang/Object` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#tag()` |
| `https://developer.android.com/reference/java/lang/CharSequence` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#text()` |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.TabView` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#view()` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#Tab()()` |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getBadge()()` Returns an instance of `https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable` associated with this tab, null if none was initialized. |
| `https://developer.android.com/reference/java/lang/CharSequence` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getContentDescription()()` Gets a brief description of this tab's content for use in accessibility support. |
| `View` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getCustomView()()` Returns the custom view used for this tab. |
| `Drawable` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getIcon()()` Return the icon associated with this tab. |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getId()()` Returns the id for this tab, `View.NO_ID` if not set. |
| `https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getOrCreateBadge()()` Creates an instance of `https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable` if none exists. |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getPosition()()` Return the current position of this tab in the tab layout. |
| `int` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getTabLabelVisibility()()` Gets the visibility mode for the Labels in this Tab. |
| `https://developer.android.com/reference/java/lang/Object` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getTag()()` |
| `https://developer.android.com/reference/java/lang/CharSequence` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getText()()` Return the text of this tab. |
| `boolean` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#isSelected()()` Returns true if this tab is currently selected. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#removeBadge()()` Removes the `https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable`. |
| `void` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#select()()` Select this tab. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setContentDescription(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence contentDesc)` Set a description of this tab's content for use in accessibility support. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setContentDescription(int)(int resId)` Set a description of this tab's content for use in accessibility support. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setCustomView(int)(int resId)` Set a custom view to be used for this tab. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setCustomView(View)(View view)` Set a custom view to be used for this tab. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setIcon(Drawable)(Drawable icon)` Set the icon displayed on this tab. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setIcon(int)(int resId)` Set the icon displayed on this tab. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setId(int)(int id)` Give this tab an id, useful for testing. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setTabLabelVisibility(int)(int mode)` Sets the visibility mode for the Labels in this Tab. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setTag(java.lang.Object)(https://developer.android.com/reference/java/lang/Object tag)` Give this Tab an arbitrary object to hold for later use. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setText(int)(int resId)` Set the text displayed on this tab. |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setText(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence text)` 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 |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#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 `https://developer.android.com/reference/com/google/android/material/badge/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 |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | Description of this tab's content |

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

### getCustomView

```
public View getCustomView()
```

Returns the custom view used for this tab.

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

### 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 `https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable` if none exists. Initializes (if needed) and returns the associated instance of `https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable`.

| Returns |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/badge/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 `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#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 `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#TAB_LABEL_VISIBILITY_UNLABELED()` or `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#TAB_LABEL_VISIBILITY_LABELED()`. |

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

### getTag

```
public Object getTag()
```

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/Object` | This Tab's tag object. |

### getText

```
public CharSequence getText()
```

Return the text of this tab.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | The tab's text |

### isSelected

```
public boolean isSelected()
```

Returns true if this tab is currently selected.

### removeBadge

```
public void removeBadge()
```

Removes the `https://developer.android.com/reference/com/google/android/material/badge/BadgeDrawable`. Do nothing if none exists. Consider changing the visibility of the `https://developer.android.com/reference/com/google/android/material/badge/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 |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence contentDesc` | Description of this tab's content |

| Returns |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | The current instance for call chaining |

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

### 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 |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | The current instance for call chaining |

| See also |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setContentDescription(java.lang.CharSequence)` |   |
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#getContentDescription()` |   |

### 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 `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setText(java.lang.CharSequence)`. Similarly, if this layout contains an ImageView with ID icon then it will be updated with the value given to `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setIcon(Drawable)`.

| Parameters |
|---|---|
| `int resId` | A layout resource to inflate and use as a custom tab view |

| Returns |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/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 `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setText(java.lang.CharSequence)`. Similarly, if this layout contains an ImageView with ID icon then it will be updated with the value given to `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab#setIcon(Drawable)`.

| Parameters |
|---|---|
| `View view` | Custom view to be used as a tab. |

| Returns |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/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 |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/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 |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/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 `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#setupWithViewPager(ViewPager)`

| 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:

- `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#TAB_LABEL_VISIBILITY_UNLABELED()`: Tabs will appear without labels regardless of whether text is set.
- `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout#TAB_LABEL_VISIBILITY_LABELED()`: Tabs will appear labeled if text is set.

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

| Returns |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/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 |
|---|---|
| `https://developer.android.com/reference/java/lang/Object tag` | Object to store |

| Returns |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/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 |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/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 |
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence text` | The text to display |

| Returns |
|---|---|
| `https://developer.android.com/reference/com/google/android/material/tabs/TabLayout.Tab` | The current instance for call chaining |