public static final class TabLayout.Tab extends Object
TabLayout.newTab()
.Modifier and Type | Field and Description |
---|---|
static int |
INVALID_POSITION
An invalid position for a tab.
|
Modifier and Type | Method and Description |
---|---|
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(CharSequence contentDesc)
Set a description of this tab's content for use in accessibility support.
|
TabLayout.Tab |
setContentDescription(int resId)
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 |
setTag(Object tag)
Give this Tab an arbitrary object to hold for later use.
|
TabLayout.Tab |
setText(CharSequence text)
Set the text displayed on this tab.
|
TabLayout.Tab |
setText(int resId)
Set the text displayed on this tab.
|
public static final int INVALID_POSITION
getPosition()
,
Constant Field Values@NonNull public TabLayout.Tab setTag(@Nullable Object tag)
tag
- Object to store@Nullable public View getCustomView()
setCustomView(View)
,
setCustomView(int)
@NonNull public TabLayout.Tab setCustomView(@Nullable View view)
If the provided view contains a TextView
with an ID of
android.R.id#text1
then that will be updated with the value given
to setText(CharSequence)
. Similarly, if this layout contains an
ImageView
with ID android.R.id#icon
then it will be updated with
the value given to setIcon(Drawable)
.
view
- Custom view to be used as a tab.@NonNull public TabLayout.Tab setCustomView(@LayoutRes int resId)
If the inflated layout contains a TextView
with an ID of
android.R.id#text1
then that will be updated with the value given
to setText(CharSequence)
. Similarly, if this layout contains an
ImageView
with ID android.R.id#icon
then it will be updated with
the value given to setIcon(Drawable)
.
resId
- A layout resource to inflate and use as a custom tab view@Nullable public Drawable getIcon()
public int getPosition()
INVALID_POSITION
if this tab is not currently in
the action bar.@Nullable public CharSequence getText()
@NonNull public TabLayout.Tab setIcon(@Nullable Drawable icon)
icon
- The drawable to use as an icon@NonNull public TabLayout.Tab setIcon(@DrawableRes int resId)
resId
- A resource ID referring to the icon that should be displayed@NonNull public TabLayout.Tab setText(@Nullable CharSequence text)
text
- The text to display@NonNull public TabLayout.Tab setText(@StringRes int resId)
resId
- A resource ID referring to the text that should be displayedpublic void select()
public boolean isSelected()
@NonNull public TabLayout.Tab setContentDescription(@StringRes int resId)
resId
- A resource ID referring to the description textsetContentDescription(CharSequence)
,
getContentDescription()
@NonNull public TabLayout.Tab setContentDescription(@Nullable CharSequence contentDesc)
contentDesc
- Description of this tab's contentsetContentDescription(int)
,
getContentDescription()
@Nullable public CharSequence getContentDescription()
setContentDescription(CharSequence)
,
setContentDescription(int)