How To Set Default Tab In Android
TabLayout
public class TabLayout
extends HorizontalScrollView
| java.lang.Object | |||||
| ↳ | android.view.View | ||||
| ↳ | android.view.ViewGroup | ||||
| ↳ | android.widget.FrameLayout | ||||
| ↳ | android.widget.HorizontalScrollView | ||||
| ↳ | com.google.android.material.tabs.TabLayout | ||||
TabLayout provides a horizontal layout to display tabs.
Population of the tabs to display is washed through TabLayout.Tab instances. You create tabs via newTab(). From in that location y'all tin can change the tab's label or icon via TabLayout.Tab.setText(int) and TabLayout.Tab.setIcon(int) respectively. To display the tab, you need to add information technology to the layout via one of the addTab(Tab) methods. For instance:
TabLayout tabLayout = ...; tabLayout.addTab(tabLayout.newTab().setText("Tab 1")); tabLayout.addTab(tabLayout.newTab().setText("Tab 2")); tabLayout.addTab(tabLayout.newTab().setText("Tab three")); You should add a listener via addOnTabSelectedListener(OnTabSelectedListener) to be notified when whatever tab's option state has been changed.
You can also add together items to TabLayout in your layout through the use of TabItem. An example usage is similar so:
<com.google.android.material.tabs.TabLayout android:layout_height="wrap_content" android:layout_width="match_parent"> <com.google.android.cloth.tabs.TabItem android:text="@string/tab_text"/> <com.google.android.fabric.tabs.TabItem android:icon="@drawable/ic_android"/> </com.google.android.fabric.tabs.TabLayout>
If you're using a ViewPager together with this layout, you can call setupWithViewPager(ViewPager) to link the 2 together. This layout will be automatically populated from the PagerAdapter's folio titles.
This view besides supports being used as part of a ViewPager'due south decor, and can be added directly to the ViewPager in a layout resource file like then:
<androidx.viewpager.widget.ViewPager android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.tabs.TabLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="elevation" /> </androidx.viewpager.widget.ViewPager>
Summary
Nested classes | |
|---|---|
interface | TabLayout.BaseOnTabSelectedListener<T extends TabLayout.Tab> This interface is deprecated. Use |
interface | TabLayout.OnTabSelectedListener Callback interface invoked when a tab's selection state changes. |
class | TabLayout.Tab A tab in this layout. |
class | TabLayout.TabLayoutOnPageChangeListener A |
class | TabLayout.TabView A |
form | TabLayout.ViewPagerOnTabSelectedListener A |
XML attributes | |
|---|---|
TabLayout_tabBackground | |
TabLayout_tabContentStart | |
TabLayout_tabGravity | |
TabLayout_tabIndicatorAnimationMode | |
TabLayout_tabIndicatorColor | |
TabLayout_tabIndicatorFullWidth | |
TabLayout_tabIndicatorGravity | |
TabLayout_tabIndicatorHeight | |
TabLayout_tabInlineLabel | |
TabLayout_tabMaxWidth | |
TabLayout_tabMinWidth | |
TabLayout_tabMode | |
TabLayout_tabPadding | |
TabLayout_tabPaddingBottom | |
TabLayout_tabPaddingEnd | |
TabLayout_tabPaddingStart | |
TabLayout_tabPaddingTop | |
TabLayout_tabRippleColor | |
TabLayout_tabSelectedTextColor | |
TabLayout_tabTextAppearance | |
TabLayout_tabTextColor | |
TabLayout_tabUnboundedRipple | |
Constants | |
|---|---|
int | GRAVITY_CENTER Gravity used to lay out the tabs in the center of the |
int | GRAVITY_FILL Gravity used to make full the |
int | GRAVITY_START Gravity used to lay out the tabs aligned to the commencement of the |
int | INDICATOR_ANIMATION_MODE_ELASTIC Indicator animation mode used to translate the selected tab indicator by growing and then shrinking the indicator, making the indicator await like it is stretching while translating between destinations. |
int | INDICATOR_ANIMATION_MODE_LINEAR Indicator animation manner used to interpret the selected tab indicator between two tabs using a linear move. |
int | INDICATOR_GRAVITY_BOTTOM Indicator gravity used to align the tab option indicator to the lesser of the |
int | INDICATOR_GRAVITY_CENTER Indicator gravity used to align the tab selection indicator to the center of the |
int | INDICATOR_GRAVITY_STRETCH Indicator gravity used to stretch the tab selection indicator beyond the entire height and width of the |
int | INDICATOR_GRAVITY_TOP Indicator gravity used to align the tab choice indicator to the top of the |
int | MODE_AUTO Auto-sizing tabs behave like MODE_FIXED with GRAVITY_CENTER while the tabs fit within the TabLayout'south content width. |
int | MODE_FIXED Fixed tabs display all tabs meantime and are best used with content that benefits from quick pivots between tabs. |
int | MODE_SCROLLABLE Scrollable tabs display a subset of tabs at whatsoever given moment, and can contain longer tab labels and a larger number of tabs. |
int | TAB_LABEL_VISIBILITY_LABELED This manner is fix by default. |
int | TAB_LABEL_VISIBILITY_UNLABELED If a tab is instantiated with |
Inherited constants |
|---|
Inherited fields |
|---|
Public constructors | |
|---|---|
TabLayout(Context context) | |
TabLayout(Context context, AttributeSet attrs) | |
TabLayout(Context context, AttributeSet attrs, int defStyleAttr) | |
Public methods | |
|---|---|
void | addOnTabSelectedListener(TabLayout.OnTabSelectedListener listener) Add a |
void | addOnTabSelectedListener(BaseOnTabSelectedListener listener) This method is deprecated. employ |
void | addTab(TabLayout.Tab tab) Add together a tab to this layout. |
void | addTab(TabLayout.Tab tab, boolean setSelected) Add a tab to this layout. |
void | addTab(TabLayout.Tab tab, int position) Add a tab to this layout. |
void | addTab(TabLayout.Tab tab, int position, boolean setSelected) Add a tab to this layout. |
void | addView(View child, int index) |
void | addView(View child, ViewGroup.LayoutParams params) |
void | addView(View child, int index, ViewGroup.LayoutParams params) |
void | addView(View kid) |
void | clearOnTabSelectedListeners() Remove all previously added |
FrameLayout.LayoutParams | generateLayoutParams(AttributeSet attrs) |
int | getSelectedTabPosition() Returns the position of the current selected tab. |
TabLayout.Tab | getTabAt(int alphabetize) Returns the tab at the specified index. |
int | getTabCount() Returns the number of tabs currently registered with the action bar. |
int | getTabGravity() The current gravity used for laying out tabs. |
ColorStateList | getTabIconTint() Gets the icon tint for the different states (normal, selected) used for the tabs. |
int | getTabIndicatorAnimationMode() Get the current indicator blitheness way used to breathing the option indicator between destinations. |
int | getTabIndicatorGravity() Get the current indicator gravity used to align the tab choice indicator in the |
int | getTabMode() Returns the current mode used past this |
ColorStateList | getTabRippleColor() Returns the ripple colour for this TabLayout. |
Drawable | getTabSelectedIndicator() Returns the option indicator drawable for this TabLayout. |
ColorStateList | getTabTextColors() Gets the text colors for the different states (normal, selected) used for the tabs. |
boolean | hasUnboundedRipple() Returns whether this |
boolean | isInlineLabel() Returns whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons. |
boolean | isTabIndicatorFullWidth() Become whether or not pick indicator width is fit to total width of the tab item, or fit to the tab detail's content. |
TabLayout.Tab | newTab() Create and return a new |
void | onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) |
void | removeAllTabs() Remove all tabs from the action bar and deselect the current tab. |
void | removeOnTabSelectedListener(TabLayout.OnTabSelectedListener listener) Remove the given |
void | removeOnTabSelectedListener(BaseOnTabSelectedListener listener) This method is deprecated. use |
void | removeTab(TabLayout.Tab tab) Remove a tab from the layout. |
void | removeTabAt(int position) Remove a tab from the layout. |
void | selectTab(TabLayout.Tab tab) Selects the given tab. |
void | selectTab(TabLayout.Tab tab, boolean updateIndicator) Selects the given tab. |
void | setElevation(bladder pinnacle) |
void | setInlineLabel(boolean inline) Set whether tab labels will be displayed inline with tab icons, or if they volition exist displayed underneath tab icons. |
void | setInlineLabelResource(int inlineResourceId) Set whether tab labels will exist displayed inline with tab icons, or if they will be displayed underneath tab icons. |
void | setOnTabSelectedListener(BaseOnTabSelectedListener listener) This method is deprecated. Use |
void | setOnTabSelectedListener(TabLayout.OnTabSelectedListener listener) This method is deprecated. Use |
void | setScrollPosition(int position, float positionOffset, boolean updateSelectedText, boolean updateIndicatorPosition) Set up the curlicue position of the tabs. |
void | setScrollPosition(int position, float positionOffset, boolean updateSelectedText) Set the whorl position of the tabs. |
void | setSelectedTabIndicator(Drawable tabSelectedIndicator) Sets the pick indicator for this TabLayout. |
void | setSelectedTabIndicator(int tabSelectedIndicatorResourceId) Sets the drawable resource to use as the pick indicator for this TabLayout. |
void | setSelectedTabIndicatorColor(int color) Sets the tab indicator's colour for the currently selected tab. |
void | setSelectedTabIndicatorGravity(int indicatorGravity) Fix the indicator gravity used to align the tab selection indicator in the |
void | setSelectedTabIndicatorHeight(int height) This method is deprecated. If possible, set the intrinsic height direct on a custom indicator drawable passed to |
void | setTabGravity(int gravity) Ready the gravity to apply when laying out the tabs. |
void | setTabIconTint(ColorStateList iconTint) Sets the icon tint for the different states (normal, selected) used for the tabs. |
void | setTabIconTintResource(int iconTintResourceId) Sets the icon tint resource for the different states (normal, selected) used for the tabs. |
void | setTabIndicatorAnimationMode(int tabIndicatorAnimationMode) Set the mode past which the selection indicator should animate when moving between destinations. |
void | setTabIndicatorFullWidth(boolean tabIndicatorFullWidth) Enable or disable choice to fit the tab selection indicator to the total width of the tab item rather than to the tab item'south content. |
void | setTabMode(int mode) Set the behavior manner for the Tabs in this layout. |
void | setTabRippleColor(ColorStateList colour) Sets the ripple color for this TabLayout. |
void | setTabRippleColorResource(int tabRippleColorResourceId) Sets the ripple color resource for this TabLayout. |
void | setTabTextColors(int normalColor, int selectedColor) Sets the text colors for the dissimilar states (normal, selected) used for the tabs. |
void | setTabTextColors(ColorStateList textColor) Sets the text colors for the different states (normal, selected) used for the tabs. |
void | setTabsFromPagerAdapter(PagerAdapter adapter) This method is deprecated. Use |
void | setUnboundedRipple(boolean unboundedRipple) Set whether this |
void | setUnboundedRippleResource(int unboundedRippleResourceId) Set whether this |
void | setupWithViewPager(ViewPager viewPager) The i-stop shop for setting up this |
void | setupWithViewPager(ViewPager viewPager, boolean autoRefresh) The one-stop shop for setting up this |
boolean | shouldDelayChildPressedState() |
Protected methods | |
|---|---|
TabLayout.Tab | createTabFromPool() |
void | onAttachedToWindow() |
void | onDetachedFromWindow() |
void | onDraw(Sheet canvas) |
void | onMeasure(int widthMeasureSpec, int heightMeasureSpec) |
boolean | releaseFromTabPool(TabLayout.Tab tab) |
Inherited methods | |
|---|---|
XML attributes
TabLayout_tabBackground
TabLayout_tabContentStart
TabLayout_tabGravity
Related methods:
-
setTabGravity(int)
TabLayout_tabIndicatorAnimationMode
Related methods:
-
setTabIndicatorAnimationMode(int)
TabLayout_tabIndicatorColor
Related methods:
-
setSelectedTabIndicatorColor(int)
TabLayout_tabIndicatorFullWidth
Related methods:
-
setTabIndicatorFullWidth(boolean)
TabLayout_tabIndicatorGravity
Related methods:
-
setSelectedTabIndicatorGravity(int)
TabLayout_tabIndicatorHeight
Related methods:
-
setSelectedTabIndicatorHeight(int)
TabLayout_tabInlineLabel
Related methods:
-
setInlineLabelResource(int)
TabLayout_tabMaxWidth
TabLayout_tabMinWidth
TabLayout_tabMode
Related methods:
-
setTabMode(int)
TabLayout_tabPadding
TabLayout_tabPaddingBottom
TabLayout_tabPaddingEnd
TabLayout_tabPaddingStart
TabLayout_tabPaddingTop
TabLayout_tabRippleColor
Related methods:
-
setTabRippleColor(ColorStateList)
TabLayout_tabSelectedTextColor
Related methods:
-
setTabTextColors(int,int)
TabLayout_tabTextAppearance
TabLayout_tabTextColor
Related methods:
-
setTabTextColors(int,int)
TabLayout_tabUnboundedRipple
Related methods:
-
setUnboundedRippleResource(int)
Constants
GRAVITY_CENTER
public static final int GRAVITY_CENTER
Gravity used to lay out the tabs in the eye of the TabLayout.
Constant Value: one (0x00000001)
GRAVITY_FILL
public static final int GRAVITY_FILL
Gravity used to make full the TabLayout every bit much as possible. This choice only takes upshot when used with MODE_FIXED on non-landscape screens less than 600dp wide.
Abiding Value: 0 (0x00000000)
GRAVITY_START
public static concluding int GRAVITY_START
Gravity used to lay out the tabs aligned to the start of the TabLayout.
Constant Value: 2 (0x00000002)
INDICATOR_ANIMATION_MODE_ELASTIC
public static final int INDICATOR_ANIMATION_MODE_ELASTIC
Indicator animation manner used to translate the selected tab indicator by growing and so shrinking the indicator, making the indicator look like information technology is stretching while translating between destinations.
The left and correct side of the choice indicator translate out of footstep - with the right decelerating and the left accelerating (when moving right). This departure in velocity between the sides of the indicator, over the duration of the animation, make the indicator look like it grows and then shrinks back down to fit it's new destination'south width.
Constant Value: 1 (0x00000001)
INDICATOR_ANIMATION_MODE_LINEAR
public static final int INDICATOR_ANIMATION_MODE_LINEAR
Indicator animation mode used to translate the selected tab indicator between 2 tabs using a linear motion.
The left and right side of the selection indicator translate in footstep over the elapsing of the animation. The only exception to this is when the indicator needs to modify size to fit the width of its new destination tab'south characterization.
Constant Value: 0 (0x00000000)
INDICATOR_GRAVITY_BOTTOM
public static final int INDICATOR_GRAVITY_BOTTOM
Indicator gravity used to align the tab choice indicator to the lesser of the TabLayout. This will just take effect if the indicator summit is set up via the custom indicator drawable's intrinsic height (preferred), via the tabIndicatorHeight aspect (deprecated), or via setSelectedTabIndicatorHeight(int) (deprecated). Otherwise, the indicator will not exist shown. This is the default value.
Constant Value: 0 (0x00000000)
INDICATOR_GRAVITY_CENTER
public static last int INDICATOR_GRAVITY_CENTER
Indicator gravity used to align the tab pick indicator to the center of the TabLayout. This will only take effect if the indicator top is set via the custom indicator drawable'south intrinsic height (preferred), via the tabIndicatorHeight attribute (deprecated), or via setSelectedTabIndicatorHeight(int) (deprecated). Otherwise, the indicator will non be shown.
Constant Value: ane (0x00000001)
INDICATOR_GRAVITY_STRETCH
public static final int INDICATOR_GRAVITY_STRETCH
Indicator gravity used to stretch the tab option indicator across the entire height and width of the TabLayout. This will disregard tabIndicatorHeight and the indicator drawable's intrinsic meridian, if fix.
Constant Value: 3 (0x00000003)
INDICATOR_GRAVITY_TOP
public static final int INDICATOR_GRAVITY_TOP
Indicator gravity used to align the tab selection indicator to the top of the TabLayout. This volition only have effect if the indicator height is set up via the custom indicator drawable's intrinsic height (preferred), via the tabIndicatorHeight attribute (deprecated), or via setSelectedTabIndicatorHeight(int) (deprecated). Otherwise, the indicator volition not be shown.
Constant Value: 2 (0x00000002)
MODE_AUTO
public static concluding int MODE_AUTO
Auto-sizing tabs carry similar MODE_FIXED with GRAVITY_CENTER while the tabs fit inside the TabLayout'south content width. Fixed tabs have equal width, based on the widest tab characterization. Once the tabs outgrow the view's width, auto-sizing tabs behave like MODE_SCROLLABLE, allowing for a dynamic number of tabs without requiring additional layout logic.
Constant Value: two (0x00000002)
MODE_FIXED
public static final int MODE_FIXED
Fixed tabs display all tabs concurrently and are best used with content that benefits from quick pivots between tabs. The maximum number of tabs is limited past the view's width. Fixed tabs have equal width, based on the widest tab label.
Constant Value: 1 (0x00000001)
MODE_SCROLLABLE
public static last int MODE_SCROLLABLE
Scrollable tabs brandish a subset of tabs at any given moment, and can comprise longer tab labels and a larger number of tabs. They are best used for browsing contexts in touch interfaces when users don't need to direct compare the tab labels.
Constant Value: 0 (0x00000000)
TAB_LABEL_VISIBILITY_LABELED
public static final int TAB_LABEL_VISIBILITY_LABELED
This mode is set up by default. If a tab is instantiated with TabLayout.Tab.setText(CharSequence), a visible label will exist created.
Constant Value: 1 (0x00000001)
TAB_LABEL_VISIBILITY_UNLABELED
public static final int TAB_LABEL_VISIBILITY_UNLABELED
If a tab is instantiated with TabLayout.Tab.setText(CharSequence), and this mode is prepare, the text will exist saved and utilized for the content description, but no visible labels will exist created.
Constant Value: 0 (0x00000000)
Public constructors
TabLayout
public TabLayout (Context context)
| Parameters | |
|---|---|
context | Context |
TabLayout
public TabLayout (Context context, AttributeSet attrs)
| Parameters | |
|---|---|
context | Context |
attrs | AttributeSet |
TabLayout
public TabLayout (Context context, AttributeSet attrs, int defStyleAttr)
| Parameters | |
|---|---|
context | Context |
attrs | AttributeSet |
defStyleAttr | int |
Public methods
addTab
public void addTab (TabLayout.Tab tab)
Add a tab to this layout. The tab will exist added at the end of the list. If this is the first tab to be added it volition become the selected tab.
| Parameters | |
|---|---|
tab | TabLayout.Tab: Tab to add |
addTab
public void addTab (TabLayout.Tab tab, boolean setSelected)
Add together a tab to this layout. The tab will exist added at the end of the listing.
| Parameters | |
|---|---|
tab | TabLayout.Tab: Tab to add together |
setSelected | boolean: True if the added tab should become the selected tab. |
addTab
public void addTab (TabLayout.Tab tab, int position)
Add together a tab to this layout. The tab will be inserted at position. If this is the first tab to be added information technology will go the selected tab.
| Parameters | |
|---|---|
tab | TabLayout.Tab: The tab to add |
position | int: The new position of the tab |
addTab
public void addTab (TabLayout.Tab tab, int position, boolean setSelected)
Add together a tab to this layout. The tab will be inserted at position.
| Parameters | |
|---|---|
tab | TabLayout.Tab: The tab to add |
position | int: The new position of the tab |
setSelected | boolean: True if the added tab should become the selected tab. |
addView
public void addView (View child, int index)
| Parameters | |
|---|---|
child | View |
index | int |
addView
public void addView (View child, ViewGroup.LayoutParams params)
| Parameters | |
|---|---|
child | View |
params | ViewGroup.LayoutParams |
addView
public void addView (View child, int index, ViewGroup.LayoutParams params)
| Parameters | |
|---|---|
child | View |
index | int |
params | ViewGroup.LayoutParams |
addView
public void addView (View child)
| Parameters | |
|---|---|
kid | View |
generateLayoutParams
public FrameLayout.LayoutParams generateLayoutParams (AttributeSet attrs)
| Parameters | |
|---|---|
attrs | AttributeSet |
| Returns | |
|---|---|
FrameLayout.LayoutParams | |
getSelectedTabPosition
public int getSelectedTabPosition ()
Returns the position of the current selected tab.
| Returns | |
|---|---|
int | selected tab position, or -1 if there isn't a selected tab. |
getTabAt
public TabLayout.Tab getTabAt (int index)
Returns the tab at the specified alphabetize.
| Parameters | |
|---|---|
index | int |
| Returns | |
|---|---|
TabLayout.Tab | |
getTabCount
public int getTabCount ()
Returns the number of tabs currently registered with the activeness bar.
| Returns | |
|---|---|
int | Tab count |
getTabGravity
public int getTabGravity ()
The current gravity used for laying out tabs.
| Returns | |
|---|---|
int | 1 of GRAVITY_CENTER or GRAVITY_FILL. |
getTabIconTint
public ColorStateList getTabIconTint ()
Gets the icon tint for the dissimilar states (normal, selected) used for the tabs.
| Returns | |
|---|---|
ColorStateList | |
getTabMode
public int getTabMode ()
Returns the current mode used by this TabLayout.
| Returns | |
|---|---|
int | |
getTabRippleColor
public ColorStateList getTabRippleColor ()
Returns the ripple color for this TabLayout.
| Returns | |
|---|---|
ColorStateList | the color (or ColorStateList) used for the ripple |
getTabSelectedIndicator
public Drawable getTabSelectedIndicator ()
Returns the selection indicator drawable for this TabLayout.
| Returns | |
|---|---|
Drawable | The drawable used as the tab pick indicator, if set. |
getTabTextColors
public ColorStateList getTabTextColors ()
Gets the text colors for the different states (normal, selected) used for the tabs.
| Returns | |
|---|---|
ColorStateList | |
hasUnboundedRipple
public boolean hasUnboundedRipple ()
Returns whether this TabLayout has an unbounded ripple effect, or if ripple is bound to the tab item size.
Related XML Attributes:
- TabLayout_tabUnboundedRipple
| Returns | |
|---|---|
boolean | |
isInlineLabel
public boolean isInlineLabel ()
Returns whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.
Related XML Attributes:
- TabLayout_tabInlineLabel
| Returns | |
|---|---|
boolean | |
isTabIndicatorFullWidth
public boolean isTabIndicatorFullWidth ()
Get whether or non choice indicator width is fit to full width of the tab item, or fit to the tab item'due south content.
Related XML Attributes:
- TabLayout_tabIndicatorFullWidth
| Returns | |
|---|---|
boolean | whether or non option indicator width is fit to the full width of the tab item |
onInitializeAccessibilityNodeInfo
public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)
| Parameters | |
|---|---|
info | AccessibilityNodeInfo |
removeAllTabs
public void removeAllTabs ()
Remove all tabs from the action bar and deselect the current tab.
removeTab
public void removeTab (TabLayout.Tab tab)
Remove a tab from the layout. If the removed tab was selected information technology will exist deselected and some other tab volition exist selected if nowadays.
| Parameters | |
|---|---|
tab | TabLayout.Tab: The tab to remove |
removeTabAt
public void removeTabAt (int position)
Remove a tab from the layout. If the removed tab was selected it will be deselected and some other tab will be selected if present.
| Parameters | |
|---|---|
position | int: Position of the tab to remove |
selectTab
public void selectTab (TabLayout.Tab tab)
Selects the given tab.
| Parameters | |
|---|---|
tab | TabLayout.Tab: The tab to select, or null to select none. |
selectTab
public void selectTab (TabLayout.Tab tab, boolean updateIndicator)
Selects the given tab. Volition e'er breathing to the selected tab if the electric current tab is reselected, regardless of the value of updateIndicator.
| Parameters | |
|---|---|
tab | TabLayout.Tab: The tab to select, or goose egg to select none. |
updateIndicator | boolean: Whether to animate to the selected tab. |
setElevation
public void setElevation (float tiptop)
| Parameters | |
|---|---|
elevation | bladder |
setInlineLabel
public void setInlineLabel (boolean inline)
Prepare whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.
Related XML Attributes:
- TabLayout_tabInlineLabel
| Parameters | |
|---|---|
inline | boolean |
setInlineLabelResource
public void setInlineLabelResource (int inlineResourceId)
Set whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.
Related XML Attributes:
- TabLayout_tabInlineLabel
| Parameters | |
|---|---|
inlineResourceId | int: Resource ID for boolean inline flag |
setScrollPosition
public void setScrollPosition (int position, bladder positionOffset, boolean updateSelectedText, boolean updateIndicatorPosition)
Set the scroll position of the tabs. This is useful for when the tabs are being displayed as part of a scrolling container such as ViewPager.
Calling this method does not update the selected tab, it is but used for drawing purposes.
| Parameters | |
|---|---|
position | int: current scroll position |
positionOffset | float: Value from [0, 1) indicating the offset from position. |
updateSelectedText | boolean: Whether to update the text's selected state. |
updateIndicatorPosition | boolean: Whether to fix the indicator to the given position and offset. |
setScrollPosition
public void setScrollPosition (int position, bladder positionOffset, boolean updateSelectedText)
Set the scroll position of the tabs. This is useful for when the tabs are existence displayed as part of a scrolling container such as ViewPager.
Calling this method does non update the selected tab, it is just used for cartoon purposes.
| Parameters | |
|---|---|
position | int: current ringlet position |
positionOffset | float: Value from [0, 1) indicating the start from position. |
updateSelectedText | boolean: Whether to update the text's selected state. |
setSelectedTabIndicator
public void setSelectedTabIndicator (Drawable tabSelectedIndicator)
Sets the selection indicator for this TabLayout. By default, this is a line along the lesser of the tab. If tabIndicatorColor is specified via the TabLayout's style or via setSelectedTabIndicatorColor(int) the selection indicator will be tinted that color. Otherwise, it will utilize the colors specified in the drawable.
Setting the indicator drawable to null will cause TabLayout to utilize the default, GradientDrawable line indicator.
| Parameters | |
|---|---|
tabSelectedIndicator | Drawable: A drawable to apply as the selected tab indicator. |
setSelectedTabIndicator
public void setSelectedTabIndicator (int tabSelectedIndicatorResourceId)
Sets the drawable resource to use equally the selection indicator for this TabLayout. Past default, this is a line along the bottom of the tab. If tabIndicatorColor is specified via the TabLayout's style or via setSelectedTabIndicatorColor(int) the selection indicator will be tinted that colour. Otherwise, it will use the colors specified in the drawable.
| Parameters | |
|---|---|
tabSelectedIndicatorResourceId | int: A drawable resource to use as the selected tab indicator. |
setSelectedTabIndicatorColor
public void setSelectedTabIndicatorColor (int color)
Sets the tab indicator'southward color for the currently selected tab.
If the tab indicator colour is not Color.TRANSPARENT, the indicator will exist wrapped and tinted right before information technology is drawn by Fault(/SlidingTabIndicator#describe(Sheet)). If you'd like the inherent colour or the tinted color of a custom drawable to be used, make sure this color is set up to Color.TRANSPARENT to avert your colour/tint being overriden.
Related XML Attributes:
- TabLayout_tabIndicatorColor
| Parameters | |
|---|---|
colour | int: colour to utilise for the indicator |
setSelectedTabIndicatorHeight
public void setSelectedTabIndicatorHeight (int acme)
This method is deprecated.
If possible, set the intrinsic meridian direct on a custom indicator drawable passed to setSelectedTabIndicator(Drawable).
Sets the tab indicator's meridian for the currently selected tab.
Related XML Attributes:
- TabLayout_tabIndicatorHeight
| Parameters | |
|---|---|
pinnacle | int: height to utilize for the indicator in pixels |
setTabIconTint
public void setTabIconTint (ColorStateList iconTint)
Sets the icon tint for the different states (normal, selected) used for the tabs.
| Parameters | |
|---|---|
iconTint | ColorStateList |
setTabIconTintResource
public void setTabIconTintResource (int iconTintResourceId)
Sets the icon tint resource for the unlike states (normal, selected) used for the tabs.
| Parameters | |
|---|---|
iconTintResourceId | int: A color resource to apply equally icon tint. |
setTabIndicatorFullWidth
public void setTabIndicatorFullWidth (boolean tabIndicatorFullWidth)
Enable or disable option to fit the tab choice indicator to the total width of the tab item rather than to the tab item'south content.
Defaults to true. If gear up to fake and the tab particular has a text label, the option indicator width will be set to the width of the text label. If the tab item has no text label, but does have an icon, the selection indicator width will exist set to the icon. If the tab item has neither of these, or if the calculated width is less than a minimum width value, the pick indicator width will be set to the minimum width value.
Related XML Attributes:
- TabLayout_tabIndicatorFullWidth
| Parameters | |
|---|---|
tabIndicatorFullWidth | boolean: Whether or not to fit selection indicator width to full width of the tab item |
setTabMode
public void setTabMode (int manner)
Set the beliefs fashion for the Tabs in this layout. The valid input options are:
-
MODE_FIXED: Stock-still tabs display all tabs concurrently and are best used with content that benefits from quick pivots between tabs. -
MODE_SCROLLABLE: Scrollable tabs brandish a subset of tabs at whatsoever given moment, and can contain longer tab labels and a larger number of tabs. They are best used for browsing contexts in bear upon interfaces when users don't need to directly compare the tab labels. This mode is commonly used with aViewPager.
Related XML Attributes:
- TabLayout_tabMode
| Parameters | |
|---|---|
style | int: i of MODE_FIXED or MODE_SCROLLABLE. |
setTabRippleColor
public void setTabRippleColor (ColorStateList color)
Sets the ripple color for this TabLayout.
When running on devices with KitKat or below, we draw this colour as a filled overlay rather than a ripple.
Related XML Attributes:
- TabLayout_tabRippleColor
| Parameters | |
|---|---|
colour | ColorStateList: color (or ColorStateList) to use for the ripple |
setTabRippleColorResource
public void setTabRippleColorResource (int tabRippleColorResourceId)
Sets the ripple color resources for this TabLayout.
When running on devices with KitKat or below, nosotros draw this colour as a filled overlay rather than a ripple.
| Parameters | |
|---|---|
tabRippleColorResourceId | int: A color resource to utilise as ripple color. |
setTabTextColors
public void setTabTextColors (int normalColor, int selectedColor)
Sets the text colors for the dissimilar states (normal, selected) used for the tabs.
Related XML Attributes:
- TabLayout_tabTextColor
- TabLayout_tabSelectedTextColor
| Parameters | |
|---|---|
normalColor | int |
selectedColor | int |
setTabTextColors
public void setTabTextColors (ColorStateList textColor)
Sets the text colors for the different states (normal, selected) used for the tabs.
| Parameters | |
|---|---|
textColor | ColorStateList |
setTabsFromPagerAdapter
public void setTabsFromPagerAdapter (PagerAdapter adapter)
This method is deprecated.
Use setupWithViewPager(ViewPager) to link a TabLayout with a ViewPager together. When that method is used, the TabLayout will exist automatically updated when the PagerAdapter is changed.
| Parameters | |
|---|---|
adapter | PagerAdapter |
setUnboundedRipple
public void setUnboundedRipple (boolean unboundedRipple)
Prepare whether this TabLayout will have an unbounded ripple effect or if ripple will exist bound to the tab item size.
Defaults to false.
Related XML Attributes:
- TabLayout_tabUnboundedRipple
| Parameters | |
|---|---|
unboundedRipple | boolean |
setUnboundedRippleResource
public void setUnboundedRippleResource (int unboundedRippleResourceId)
Set whether this TabLayout will have an unbounded ripple effect or if ripple volition be bound to the tab detail size. Defaults to false.
Related XML Attributes:
- TabLayout_tabUnboundedRipple
| Parameters | |
|---|---|
unboundedRippleResourceId | int: Resource ID for boolean unbounded ripple value |
setupWithViewPager
public void setupWithViewPager (ViewPager viewPager)
The ane-stop shop for setting upward this TabLayout with a ViewPager.
This is the same as calling setupWithViewPager(ViewPager, boolean) with auto-refresh enabled.
| Parameters | |
|---|---|
viewPager | ViewPager: the ViewPager to link to, or null to articulate any previous link |
setupWithViewPager
public void setupWithViewPager (ViewPager viewPager, boolean autoRefresh)
The one-stop shop for setting up this TabLayout with a ViewPager.
This method volition link the given ViewPager and this TabLayout together so that changes in 1 are automatically reflected in the other. This includes scroll country changes and clicks. The tabs displayed in this layout volition exist populated from the ViewPager adapter'due south page titles.
If autoRefresh is truthful, whatsoever changes in the PagerAdapter will trigger this layout to re-populate itself from the adapter'due south titles.
If the given ViewPager is non-null, it needs to already accept a PagerAdapter set.
| Parameters | |
|---|---|
viewPager | ViewPager: the ViewPager to link to, or null to articulate whatever previous link |
autoRefresh | boolean: whether this layout should refresh its contents if the given ViewPager'southward content changes |
shouldDelayChildPressedState
public boolean shouldDelayChildPressedState ()
| Returns | |
|---|---|
boolean | |
Protected methods
onAttachedToWindow
protected void onAttachedToWindow ()
onDetachedFromWindow
protected void onDetachedFromWindow ()
onDraw
protected void onDraw (Sail canvas)
| Parameters | |
|---|---|
canvas | Canvas |
onMeasure
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
| Parameters | |
|---|---|
widthMeasureSpec | int |
heightMeasureSpec | int |
releaseFromTabPool
protected boolean releaseFromTabPool (TabLayout.Tab tab)
| Parameters | |
|---|---|
tab | TabLayout.Tab |
| Returns | |
|---|---|
boolean | |
Content and lawmaking samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2022-01-19 UTC.
How To Set Default Tab In Android,
Source: https://developer.android.com/reference/com/google/android/material/tabs/TabLayout
Posted by: lynchagainto.blogspot.com

0 Response to "How To Set Default Tab In Android"
Post a Comment