TabLayout.Tab
public
static
class
TabLayout.Tab
extends Object
java.lang.Object | |
↳ | com.google.android.material.tabs.TabLayout.Tab |
A tab in this layout. Instances can be created via newTab()
.
Summary
Constants | |
---|---|
int |
INVALID_POSITION
An invalid position for a tab. |
Fields | |
---|---|
public
TabLayout |
parent
|
public
TabLayout.TabView |
view
|
Public constructors | |
---|---|
TabLayout.Tab()
|
Public methods | |
---|---|
BadgeDrawable
|
getBadge()
Returns an instance of |
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. |
BadgeDrawable
|
getOrCreateBadge()
Creates an instance of |
int
|
getPosition()
Return the current position of this tab in the action bar. |
int
|
getTabLabelVisibility()
Gets the visibility mode for the Labels in this Tab. |
Object
|
getTag()
|
CharSequence
|
getText()
Return the text of this tab. |
boolean
|
isSelected()
Returns true if this tab is currently selected. |
void
|
removeBadge()
Removes the |
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 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
|
setTabLabelVisibility(int mode)
Sets the visibility mode for the Labels in 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. |
Inherited methods | |
---|---|
![]()
java.lang.Object
|
Constants
INVALID_POSITION
int INVALID_POSITION
An invalid position for a tab.
See also:
Constant Value: -1 (0xffffffff)
Fields
Public constructors
TabLayout.Tab
TabLayout.Tab ()
Public methods
getBadge
BadgeDrawable getBadge ()
Returns an instance of BadgeDrawable
associated with this tab, null if none was
initialized.
Returns | |
---|---|
BadgeDrawable |
getContentDescription
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
View getCustomView ()
Returns the custom view used for this tab.
Returns | |
---|---|
View |
See also:
getIcon
Drawable getIcon ()
Return the icon associated with this tab.
Returns | |
---|---|
Drawable |
The tab's icon |
getOrCreateBadge
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
int getPosition ()
Return the current position of this tab in the action bar.
Returns | |
---|---|
int |
Current position, or INVALID_POSITION if this tab is not currently in the
action bar.
|
getTabLabelVisibility
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 . |
See also:
getTag
Object getTag ()
Returns | |
---|---|
Object |
This Tab's tag object. |
getText
CharSequence getText ()
Return the text of this tab.
Returns | |
---|---|
CharSequence |
The tab's text |
isSelected
boolean isSelected ()
Returns true if this tab is currently selected.
Returns | |
---|---|
boolean |
removeBadge
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
void select ()
Select this tab. Only valid if the tab has been added to the action bar.
setContentDescription
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 |
int : A resource ID referring to the description text |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining |
setContentDescription
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 |
CharSequence : Description of this tab's content |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining |
setCustomView
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(CharSequence)
. Similarly, if this layout contains an ImageView
with ID
icon
then it will be updated with the value given to setIcon(Drawable)
.
Parameters | |
---|---|
resId |
int : A layout resource to inflate and use as a custom tab view |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining |
setCustomView
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 |
View : Custom view to be used as a tab. |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining |
setIcon
TabLayout.Tab setIcon (Drawable icon)
Set the icon displayed on this tab.
Parameters | |
---|---|
icon |
Drawable : The drawable to use as an icon |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining |
setIcon
TabLayout.Tab setIcon (int resId)
Set the icon displayed on this tab.
Parameters | |
---|---|
resId |
int : A resource ID referring to the icon that should be displayed |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining |
setTabLabelVisibility
TabLayout.Tab setTabLabelVisibility (int mode)
Sets the visibility mode for the Labels in this Tab. The valid input options are:
TAB_LABEL_VISIBILITY_UNLABELED
: Tabs will appear without labels regardless of whether text is set.TAB_LABEL_VISIBILITY_LABELED
: Tabs will appear labeled if text is set.
Parameters | |
---|---|
mode |
int : one of TAB_LABEL_VISIBILITY_UNLABELED or TAB_LABEL_VISIBILITY_LABELED . |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining. |
setTag
TabLayout.Tab setTag (Object tag)
Give this Tab an arbitrary object to hold for later use.
Parameters | |
---|---|
tag |
Object : Object to store |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining |
setText
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 |
int : A resource ID referring to the text that should be displayed |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining |
setText
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 |
CharSequence : The text to display |
Returns | |
---|---|
TabLayout.Tab |
The current instance for call chaining |