Class TabLayout
- All Implemented Interfaces:
Drawable.Callback,ViewManager,ViewParent
Population of the tabs to display is done through TabLayout.Tab instances. You create tabs via
newTab(). From there you can change the tab's label or icon via TabLayout.Tab.setText(java.lang.CharSequence)
and TabLayout.Tab.setIcon(icyllis.modernui.graphics.drawable.Drawable) respectively. To display the tab, you need to add it to the layout
via one of the addTab(Tab) methods. For example:
TabLayout tabLayout = ...;
tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
You should add a listener via addOnTabSelectedListener(OnTabSelectedListener) to be
notified when any tab's selection state has been changed.
ViewPager integration
If you're using a ViewPager together with this layout, you
can call setupWithViewPager(ViewPager) to link the two together. This layout will be
automatically populated from the PagerAdapter's page titles.
This view also supports being used as part of a ViewPager's decor, and can be added directly to the ViewPager.
For more information, see the component developer guidance and design guidelines.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface invoked when a tab's selection state changes.static final classA tab in this layout.static classAViewPager.OnPageChangeListenerclass which contains the necessary calls back to the providedTabLayoutso that the tab position is kept in sync.final classstatic classATabLayout.OnTabSelectedListenerclass which contains the necessary calls back to the providedViewPagerso that the tab position is kept in sync.Nested classes/interfaces inherited from class icyllis.modernui.widget.FrameLayout
FrameLayout.LayoutParamsNested classes/interfaces inherited from class icyllis.modernui.view.ViewGroup
ViewGroup.MarginLayoutParamsNested classes/interfaces inherited from class icyllis.modernui.view.View
View.DragShadow, View.Focusable, View.FocusableMode, View.FocusDirection, View.FocusRealDirection, View.LayoutDir, View.NestedScrollType, View.OnAttachStateChangeListener, View.OnClickListener, View.OnContextClickListener, View.OnCreateContextMenuListener, View.OnDragListener, View.OnFocusChangeListener, View.OnGenericMotionListener, View.OnHoverListener, View.OnKeyListener, View.OnLayoutChangeListener, View.OnLongClickListener, View.OnScrollChangeListener, View.OnTouchListener, View.ResolvedLayoutDir, View.ScrollAxis, View.ScrollBarStyle, View.ScrollIndicators, View.TextAlignment, View.Visibility -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intGravity used to lay out the tabs in the center of theTabLayout.static final intGravity used to fill theTabLayoutas much as possible.static final intGravity used to lay out the tabs aligned to the start of theTabLayout.static final intIndicator animation mode used to translate the selected tab indicator by growing and then shrinking the indicator, making the indicator look like it is stretching while translating between destinations.static final intIndicator animation mode used to switch the selected tab indicator from one tab to another by sequentially fading it out from the current destination and in at its new destination.static final intIndicator animation mode used to translate the selected tab indicator between two tabs using a linear motion.static final intIndicator gravity used to align the tab selection indicator to the bottom of theTabLayout.static final intIndicator gravity used to align the tab selection indicator to the center of theTabLayout.static final intIndicator gravity used to stretch the tab selection indicator across the entire height of theTabLayout.static final intIndicator gravity used to align the tab selection indicator to the top of theTabLayout.static final intAuto-sizing tabs behave like MODE_FIXED with GRAVITY_CENTER while the tabs fit within the TabLayout's content width.static final intFixed tabs display all tabs concurrently and are best used with content that benefits from quick pivots between tabs.static final intScrollable tabs display a subset of tabs at any given moment, and can contain longer tab labels and a larger number of tabs.static final intThis mode is set by default.static final intIf a tab is instantiated withTabLayout.Tab.setText(CharSequence), and this mode is set, the text will be saved and utilized for the content description, but no visible labels will be created.Fields inherited from class icyllis.modernui.view.ViewGroup
CLIP_TO_PADDING_MASK, FLAG_DISALLOW_INTERCEPT, FOCUS_AFTER_DESCENDANTS, FOCUS_BEFORE_DESCENDANTS, FOCUS_BLOCK_DESCENDANTSFields inherited from class icyllis.modernui.view.View
ALPHA, BOTTOM, EMPTY_STATE_SET, ENABLED_FOCUSED_SELECTED_STATE_SET, ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_FOCUSED_STATE_SET, ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, ENABLED_SELECTED_STATE_SET, ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, ENABLED_STATE_SET, ENABLED_WINDOW_FOCUSED_STATE_SET, FOCUS_BACKWARD, FOCUS_DOWN, FOCUS_FORWARD, FOCUS_LEFT, FOCUS_RIGHT, FOCUS_UP, FOCUSABLE, FOCUSABLE_AUTO, FOCUSABLES_ALL, FOCUSABLES_TOUCH_MODE, FOCUSED_SELECTED_STATE_SET, FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, FOCUSED_STATE_SET, FOCUSED_WINDOW_FOCUSED_STATE_SET, GONE, HAPTIC_FEEDBACK_ENABLED, INVISIBLE, LAYOUT_DIRECTION_INHERIT, LAYOUT_DIRECTION_LOCALE, LAYOUT_DIRECTION_LTR, LAYOUT_DIRECTION_RTL, LAYOUT_DIRECTION_UNDEFINED, LEFT, MEASURED_HEIGHT_STATE_SHIFT, MEASURED_SIZE_MASK, MEASURED_STATE_MASK, MEASURED_STATE_TOO_SMALL, NO_ID, NOT_FOCUSABLE, OVER_SCROLL_ALWAYS, OVER_SCROLL_IF_CONTENT_SCROLLS, OVER_SCROLL_NEVER, PRESSED_ENABLED_FOCUSED_SELECTED_STATE_SET, PRESSED_ENABLED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_STATE_SET, PRESSED_ENABLED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_SELECTED_STATE_SET, PRESSED_ENABLED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_ENABLED_STATE_SET, PRESSED_ENABLED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_SELECTED_STATE_SET, PRESSED_FOCUSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_FOCUSED_STATE_SET, PRESSED_FOCUSED_WINDOW_FOCUSED_STATE_SET, PRESSED_SELECTED_STATE_SET, PRESSED_SELECTED_WINDOW_FOCUSED_STATE_SET, PRESSED_STATE_SET, PRESSED_WINDOW_FOCUSED_STATE_SET, RIGHT, ROTATION, ROTATION_X, ROTATION_Y, SCALE_X, SCALE_Y, SCROLL_AXIS_HORIZONTAL, SCROLL_AXIS_NONE, SCROLL_AXIS_VERTICAL, SCROLL_INDICATOR_BOTTOM, SCROLL_INDICATOR_END, SCROLL_INDICATOR_LEFT, SCROLL_INDICATOR_RIGHT, SCROLL_INDICATOR_START, SCROLL_INDICATOR_TOP, SCROLL_X, SCROLL_Y, SCROLLBARS_INSIDE_INSET, SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_OUTSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY, SELECTED_STATE_SET, SELECTED_WINDOW_FOCUSED_STATE_SET, SOUND_EFFECTS_ENABLED, TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_GRAVITY, TEXT_ALIGNMENT_INHERIT, TEXT_ALIGNMENT_TEXT_END, TEXT_ALIGNMENT_TEXT_START, TEXT_ALIGNMENT_VIEW_END, TEXT_ALIGNMENT_VIEW_START, TEXT_DIRECTION_ANY_RTL, TEXT_DIRECTION_FIRST_STRONG, TEXT_DIRECTION_FIRST_STRONG_LTR, TEXT_DIRECTION_FIRST_STRONG_RTL, TEXT_DIRECTION_INHERIT, TEXT_DIRECTION_LOCALE, TEXT_DIRECTION_LTR, TEXT_DIRECTION_RTL, TOP, TRANSLATION_X, TRANSLATION_Y, TRANSLATION_Z, TYPE_NON_TOUCH, TYPE_TOUCH, VIEW_MARKER, VISIBLE, WINDOW_FOCUSED_STATE_SET, X, Y, Z -
Constructor Summary
ConstructorsConstructorDescriptionTabLayout(Context context, AttributeSet attrs) TabLayout(Context context, AttributeSet attrs, ResourceId defStyleAttr) TabLayout(Context context, AttributeSet attrs, ResourceId defStyleAttr, ResourceId defStyleRes) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd aTabLayout.OnTabSelectedListenerthat will be invoked when tab selection changes.voidaddTab(TabLayout.Tab tab) Add a tab to this layout.voidaddTab(TabLayout.Tab tab, boolean setSelected) Add a tab to this layout.voidaddTab(TabLayout.Tab tab, int position) Add a tab to this layout.voidaddTab(TabLayout.Tab tab, int position, boolean setSelected) Add a tab to this layout.voidAdds a child view.voidAdds a child view.voidaddView(View child, int index, ViewGroup.LayoutParams params) Adds a child view with the specified layout parameters.voidaddView(View child, ViewGroup.LayoutParams params) Adds a child view with the specified layout parameters.voidRemove all previously addedTabLayout.OnTabSelectedListeners.intReturns the position of the current selected tab.getTabAt(int index) Returns the tab at the specified index.intReturns the number of tabs currently registered with the tab layout.intThe current gravity used for laying out tabs.Gets the icon tint for the different states (normal, selected) used for the tabs.intGet the current indicator animation mode used to animate the selection indicator between destinations.intGet the current indicator gravity used to align the tab selection indicator in theTabLayout.intReturns the current mode used by thisTabLayout.Returns the ripple color for this TabLayout.Returns the selection indicator drawable for this TabLayout.Gets the text colors for the different states (normal, selected) used for the tabs.booleanReturns whether thisTabLayouthas an unbounded ripple effect, or if ripple is bound to the tab item size.booleanReturns whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.booleanGet whether or not selection indicator width is fit to full width of the tab item, or fit to the tab item's content.newTab()Create and return a newTabLayout.Tab.protected voidThis is called when the view is attached to a window.protected voidThis is called when the view is detached from a window.protected voidDraw the content of this view, implement this to do your drawing.booleanonInterceptTouchEvent(MotionEvent event) Implement this method to intercept all touch screen motion events.protected voidonMeasure(int widthMeasureSpec, int heightMeasureSpec) Measure the view and its content to determine the measured width and the measured height.booleanonTouchEvent(MotionEvent event) Implement this method to handle touch screen motion events.voidRemove all tabs from the tab layout and deselect the current tab.voidRemove the givenTabLayout.OnTabSelectedListenerthat was previously added viaaddOnTabSelectedListener(OnTabSelectedListener).voidremoveTab(TabLayout.Tab tab) Remove a tab from the layout.voidremoveTabAt(int position) Remove a tab from the layout.voidselectTab(TabLayout.Tab tab) Selects the given tab.voidselectTab(TabLayout.Tab tab, boolean updateIndicator) Selects the given tab.voidsetInlineLabel(boolean inline) Set whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.voidsetScrollPosition(int position, float positionOffset, boolean updateSelectedTabView) Set the scroll position of theTabLayout.voidsetScrollPosition(int position, float positionOffset, boolean updateSelectedTabView, boolean updateIndicatorPosition) Set the scroll position of theTabLayout.voidsetSelectedTabIndicator(Drawable tabSelectedIndicator) Sets the selection indicator for this TabLayout.voidsetSelectedTabIndicatorColor(int color) Sets the tab indicator's color for the currently selected tab.voidsetSelectedTabIndicatorGravity(int indicatorGravity) Set the indicator gravity used to align the tab selection indicator in theTabLayout.voidsetTabGravity(int gravity) Set the gravity to use when laying out the tabs.voidsetTabIconTint(ColorStateList iconTint) Sets the icon tint for the different states (normal, selected) used for the tabs.voidsetTabIndicatorAnimationMode(int tabIndicatorAnimationMode) Set the mode by which the selection indicator should animate when moving between destinations.voidsetTabIndicatorFullWidth(boolean tabIndicatorFullWidth) Enable or disable option to fit the tab selection indicator to the full width of the tab item rather than to the tab item's content.voidsetTabMode(int mode) Set the behavior mode for the Tabs in this layout.voidsetTabRippleColor(ColorStateList color) Sets the ripple color for this TabLayout.voidsetTabTextColors(int normalColor, int selectedColor) Sets the text colors for the different states (normal, selected) used for the tabs.voidsetTabTextColors(ColorStateList textColor) Sets the text colors for the different states (normal, selected) used for the tabs.voidsetUnboundedRipple(boolean unboundedRipple) Set whether thisTabLayoutwill have an unbounded ripple effect or if ripple will be bound to the tab item size.voidsetupWithViewPager(ViewPager viewPager) voidsetupWithViewPager(ViewPager viewPager, boolean autoRefresh) booleanReturn true if the pressed state should be delayed for children or descendants of this ViewGroup.Methods inherited from class icyllis.modernui.widget.HorizontalScrollView
arrowScroll, computeHorizontalScrollOffset, computeHorizontalScrollRange, computeScroll, computeScrollDeltaToGetChildRectOnScreen, dispatchKeyEvent, draw, executeKeyEvent, fling, fullScroll, getLeftEdgeEffectBlendMode, getLeftEdgeEffectColor, getRightEdgeEffectBlendMode, getRightEdgeEffectColor, isFillViewport, isSmoothScrollingEnabled, measureChild, measureChildWithMargins, onGenericMotionEvent, onLayout, onOverScrolled, onRequestFocusInDescendants, onSizeChanged, pageScroll, requestChildFocus, requestChildRectangleOnScreen, requestDisallowInterceptTouchEvent, requestLayout, scrollTo, setEdgeEffectColor, setFillViewport, setLeftEdgeEffectBlendMode, setLeftEdgeEffectColor, setRightEdgeEffectBlendMode, setRightEdgeEffectColor, setSmoothScrollingEnabled, smoothScrollBy, smoothScrollToMethods inherited from class icyllis.modernui.widget.FrameLayout
checkLayoutParams, generateDefaultLayoutParams, generateLayoutParams, getMeasureAllChildren, setForegroundGravity, setMeasureAllChildrenMethods inherited from class icyllis.modernui.view.ViewGroup
addFocusables, addKeyboardNavigationClusters, addStatesFromChildren, addTouchables, addTransientView, addView, addViewInLayout, addViewInLayout, attachViewToParent, bringChildToFront, childDrawableStateChanged, childHasTransientStateChanged, cleanupLayoutState, clearChildFocus, clearDisappearingChildren, clearFocus, detachAllViewsFromParent, detachViewFromParent, detachViewFromParent, detachViewsFromParent, dispatchDraw, dispatchDrawableHotspotChanged, dispatchFinishTemporaryDetach, dispatchGenericPointerEvent, dispatchHoverEvent, dispatchKeyShortcutEvent, dispatchSetActivated, dispatchSetPressed, dispatchSetSelected, dispatchStartTemporaryDetach, dispatchTouchEvent, dispatchVisibilityChanged, dispatchWindowFocusChanged, dispatchWindowVisibilityChanged, drawableStateChanged, drawChild, endViewTransition, findFocus, focusableViewAvailable, focusSearch, getChildAt, getChildCount, getChildDrawingOrder, getChildDrawingOrder, getChildMeasureSpec, getChildVisibleRect, getChildVisibleRect, getClipChildren, getClipToPadding, getDescendantFocusability, getFocusedChild, getLayoutTransition, getNestedScrollAxes, getTouchscreenBlocksFocus, getTransientView, getTransientViewCount, getTransientViewIndex, hasBooleanFlag, hasFocus, hasTransientState, indexOfChild, internalSetPadding, invalidateChild, invalidateChildInParent, isChildrenDrawingOrderEnabled, isLayoutSuppressed, isTransitionGroup, jumpDrawablesToCurrentState, layout, measureChildren, offsetChildrenTopAndBottom, offsetDescendantRectToMyCoords, offsetRectIntoDescendantCoords, onChildVisibilityChanged, onCreateDrawableState, onInterceptHoverEvent, onNestedFling, onNestedPreFling, onNestedPreScroll, onNestedScroll, onNestedScrollAccepted, onResolvePointerIcon, onSetLayoutParams, onStartNestedScroll, onStopNestedScroll, onViewAdded, onViewRemoved, removeAllViews, removeAllViewsInLayout, removeDetachedView, removeTransientView, removeView, removeViewAt, removeViewInLayout, removeViews, removeViewsInLayout, requestFocus, requestTransitionStart, resetResolvedDrawables, resolveDrawables, resolveLayoutDirection, resolveLayoutParams, resolvePadding, resolveRtlPropertiesIfNeeded, resolveTextAlignment, resolveTextDirection, restoreDefaultFocus, setAddStatesFromChildren, setBooleanFlag, setChildrenDrawingOrderEnabled, setClipChildren, setClipToPadding, setDescendantFocusability, setLayoutTransition, setShadowAlpha, setTouchscreenBlocksFocus, setTransitionGroup, showContextMenuForChild, startActionModeForChild, startViewTransition, suppressLayout, transformPointToViewLocal, updateViewLayoutMethods inherited from class icyllis.modernui.view.View
addFocusables, addOnAttachStateChangeListener, addOnLayoutChangeListener, awakenScrollBars, awakenScrollBars, callOnClick, cancelLongPress, cancelPendingInputEvents, canReceivePointerEvents, canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, canScrollHorizontally, canScrollVertically, combineMeasuredStates, computeHorizontalScrollExtent, computeVerticalScrollExtent, computeVerticalScrollOffset, computeVerticalScrollRange, createContextMenu, dispatchGenericMotionEvent, dispatchNestedFling, dispatchNestedPreFling, dispatchNestedPreScroll, dispatchNestedScroll, dispatchPointerEvent, dp, drawableHotspotChanged, findViewById, findViewByPredicate, findViewByPredicateInsideOut, findViewWithTag, focusSearch, forceHasOverlappingRendering, forceLayout, generateViewId, getAlpha, getAnimationMatrix, getBackground, getBaseline, getBottom, getBoundsOnScreen, getBoundsOnScreen, getClipBounds, getClipBounds, getContentDescription, getContext, getContextMenuInfo, getDefaultSize, getDrawableState, getDrawingRect, getElevation, getFadingEdge, getFadingEdgeLength, getFocusable, getFocusables, getFocusedRect, getForeground, getForegroundGravity, getGlobalVisibleRect, getGlobalVisibleRect, getHandler, getHasOverlappingRendering, getHeight, getHitRect, getHorizontalScrollbarHeight, getHorizontalScrollbarThumbDrawable, getHorizontalScrollbarTrackDrawable, getId, getInverseMatrix, getKeyDispatcherState, getLayoutDirection, getLayoutParams, getLeft, getLocalVisibleRect, getLocationInWindow, getLocationOnScreen, getMatrix, getMeasuredHeight, getMeasuredHeightAndState, getMeasuredState, getMeasuredWidth, getMeasuredWidthAndState, getMinimumHeight, getMinimumWidth, getNextClusterForwardId, getNextFocusDownId, getNextFocusForwardId, getNextFocusLeftId, getNextFocusRightId, getNextFocusUpId, getOnFocusChangeListener, getOnLongClickListener, getOutlineProvider, getOverScrollMode, getPaddingBottom, getPaddingEnd, getPaddingLeft, getPaddingRight, getPaddingStart, getPaddingTop, getParent, getPivotX, getPivotY, getRawLayoutDirection, getRawTextAlignment, getRawTextDirection, getRevealOnFocusHint, getRight, getRootView, getRotation, getRotationX, getRotationY, getScaleX, getScaleY, getScrollBarDefaultDelayBeforeFade, getScrollBarFadeDuration, getScrollBarSize, getScrollBarStyle, getScrollIndicators, getScrollX, getScrollY, getStateDescription, getStateListAnimator, getSuggestedMinimumHeight, getSuggestedMinimumWidth, getTag, getTag, getTextAlignment, getTextDirection, getTooltipText, getTooltipView, getTop, getTouchables, getTransitionAlpha, getTransitionName, getTranslationX, getTranslationY, getTranslationZ, getVerticalFadingEdgeLength, getVerticalScrollbarThumbDrawable, getVerticalScrollbarTrackDrawable, getVerticalScrollbarWidth, getViewRoot, getViewTreeObserver, getVisibility, getWidth, getWindowAttachCount, getWindowVisibility, getX, getY, getZ, handleScrollBarDragging, hasExplicitFocusable, hasFocusable, hasIdentityMatrix, hasNestedScrollingParent, hasOnClickListeners, hasOnLongClickListeners, hasOverlappingRendering, hasTranslationTransientState, hasWindowFocus, invalidate, invalidate, invalidate, invalidateDrawable, invalidateOutline, isActivated, isAttachedToWindow, isClickable, isContextClickable, isDuplicateParentStateEnabled, isEnabled, isFocusable, isFocusableInTouchMode, isFocused, isFocusedByDefault, isForegroundInsidePadding, isHapticFeedbackEnabled, isHorizontalFadingEdgeEnabled, isHorizontalScrollBarEnabled, isHovered, isInLayout, isInScrollingContainer, isInTouchMode, isKeyboardNavigationCluster, isLaidOut, isLayoutDirectionInherited, isLayoutDirectionResolved, isLayoutRequested, isLayoutRtl, isLongClickable, isNestedScrollingEnabled, isPaddingRelative, isPivotSet, isPressed, isRootNamespace, isScrollbarFadingEnabled, isSelected, isShowingLayoutBounds, isShown, isSoundEffectsEnabled, isTemporarilyDetached, isTextAlignmentInherited, isTextAlignmentResolved, isTextDirectionInherited, isTextDirectionResolved, isVerticalFadingEdgeEnabled, isVerticalScrollBarEnabled, isVerticalScrollBarHidden, keyboardNavigationClusterSearch, mapRectFromViewToScreenCoords, measure, mergeDrawableStates, offsetLeftAndRight, offsetTopAndBottom, onCancelPendingInputEvents, onCreateContextMenu, onDragEvent, onDrawForeground, onDrawScrollBars, onFinishTemporaryDetach, onFocusChanged, onHoverChanged, onHoverEvent, onKeyDown, onKeyShortcut, onKeyUp, onResolveDrawables, onRtlPropertiesChanged, onScrollChanged, onStartTemporaryDetach, onVisibilityAggregated, onVisibilityChanged, onWindowFocusChanged, onWindowVisibilityChanged, overScrollBy, performButtonActionOnTouchDown, performClick, performContextClick, performContextClick, performHapticFeedback, performHapticFeedback, performLongClick, performLongClick, playSoundEffect, pointInView, post, postDelayed, postInvalidate, postInvalidateDelayed, postInvalidateOnAnimation, postOnAnimation, postOnAnimationDelayed, refreshDrawableState, removeCallbacks, removeOnAttachStateChangeListener, removeOnLayoutChangeListener, requestFocus, requestFocus, requestRectangleOnScreen, requestRectangleOnScreen, requireViewById, resetPivot, resolveSize, resolveSizeAndState, scheduleDrawable, scrollBy, setActivated, setAlpha, setAnimationMatrix, setBackground, setBottom, setClickable, setClipBounds, setContentDescription, setContextClickable, setDuplicateParentStateEnabled, setElevation, setEnabled, setFocusable, setFocusable, setFocusableInTouchMode, setFocusedByDefault, setFocusedInCluster, setForeground, setFrame, setHapticFeedbackEnabled, setHasTransientState, setHasTranslationTransientState, setHorizontalFadingEdgeEnabled, setHorizontalScrollBarEnabled, setHorizontalScrollbarThumbDrawable, setHorizontalScrollbarTrackDrawable, setHovered, setId, setIsRootNamespace, setKeyboardNavigationCluster, setLayoutDirection, setLayoutParams, setLeft, setLongClickable, setMeasuredDimension, setMinimumHeight, setMinimumWidth, setNestedScrollingEnabled, setNextClusterForwardId, setNextFocusDownId, setNextFocusForwardId, setNextFocusLeftId, setNextFocusRightId, setNextFocusUpId, setOnClickListener, setOnContextClickListener, setOnCreateContextMenuListener, setOnDragListener, setOnFocusChangeListener, setOnGenericMotionListener, setOnHoverListener, setOnKeyListener, setOnLongClickListener, setOnScrollChangeListener, setOnTouchListener, setOutlineProvider, setOverScrollMode, setPadding, setPaddingRelative, setPivotX, setPivotY, setPressed, setRevealOnFocusHint, setRight, setRotation, setRotationX, setRotationY, setScaleX, setScaleY, setScrollBarDefaultDelayBeforeFade, setScrollBarFadeDuration, setScrollbarFadingEnabled, setScrollBarSize, setScrollBarStyle, setScrollIndicators, setScrollIndicators, setScrollX, setScrollY, setSelected, setSoundEffectsEnabled, setStateDescription, setStateListAnimator, setTag, setTag, setTextAlignment, setTextDirection, setTooltipText, setTop, setTransitionAlpha, setTransitionName, setTransitionVisibility, setTranslationX, setTranslationY, setTranslationZ, setVerticalFadingEdgeEnabled, setVerticalScrollBarEnabled, setVerticalScrollbarThumbDrawable, setVerticalScrollbarTrackDrawable, setVisibility, setWillNotDraw, setX, setY, setZ, showContextMenu, showContextMenu, sp, startActionMode, startActionMode, startDragAndDrop, startNestedScroll, stopNestedScroll, toGlobalMotionEvent, toLocalMotionEvent, toString, transformFromViewToWindowSpace, transformMatrixToGlobal, transformMatrixToLocal, unscheduleDrawable, unscheduleDrawable, verifyDrawable, willNotDrawMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface icyllis.modernui.view.ViewParent
canResolveLayoutDirection, canResolveTextAlignment, canResolveTextDirection, createContextMenu, getLayoutDirection, getParent, getTextAlignment, getTextDirection, isLayoutDirectionResolved, isLayoutRequested, isTextAlignmentResolved, isTextDirectionResolved, keyboardNavigationClusterSearch
-
Field Details
-
MODE_SCROLLABLE
public static final int MODE_SCROLLABLEScrollable tabs display a subset of tabs at any given moment, and can contain 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 directly compare the tab labels.- See Also:
-
MODE_FIXED
public static final int MODE_FIXEDFixed 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 by the view's width. Fixed tabs have equal width, based on the widest tab label.- See Also:
-
MODE_AUTO
public static final int MODE_AUTOAuto-sizing tabs behave like MODE_FIXED with GRAVITY_CENTER while the tabs fit within the TabLayout's content width. Fixed tabs have equal width, based on the widest tab label. 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.- See Also:
-
TAB_LABEL_VISIBILITY_UNLABELED
public static final int TAB_LABEL_VISIBILITY_UNLABELEDIf a tab is instantiated withTabLayout.Tab.setText(CharSequence), and this mode is set, the text will be saved and utilized for the content description, but no visible labels will be created.- See Also:
-
TAB_LABEL_VISIBILITY_LABELED
public static final int TAB_LABEL_VISIBILITY_LABELEDThis mode is set by default. If a tab is instantiated withTabLayout.Tab.setText(CharSequence), a visible label will be created.- See Also:
-
GRAVITY_FILL
public static final int GRAVITY_FILLGravity used to fill theTabLayoutas much as possible. This option only takes effect when used withMODE_FIXEDon non-landscape screens less than 600dp wide.- See Also:
-
GRAVITY_CENTER
public static final int GRAVITY_CENTERGravity used to lay out the tabs in the center of theTabLayout.- See Also:
-
GRAVITY_START
public static final int GRAVITY_STARTGravity used to lay out the tabs aligned to the start of theTabLayout.- See Also:
-
INDICATOR_GRAVITY_BOTTOM
public static final int INDICATOR_GRAVITY_BOTTOMIndicator gravity used to align the tab selection indicator to the bottom of theTabLayout. This will only take effect if the indicator height is set via the custom indicator drawable's intrinsic height (preferred). Otherwise, the indicator will not be shown. This is the default value.- See Also:
-
INDICATOR_GRAVITY_CENTER
public static final int INDICATOR_GRAVITY_CENTERIndicator gravity used to align the tab selection indicator to the center of theTabLayout. This will only take effect if the indicator height is set via the custom indicator drawable's intrinsic height (preferred). Otherwise, the indicator will not be shown.- See Also:
-
INDICATOR_GRAVITY_TOP
public static final int INDICATOR_GRAVITY_TOPIndicator gravity used to align the tab selection indicator to the top of theTabLayout. This will only take effect if the indicator height is set via the custom indicator drawable's intrinsic height (preferred). Otherwise, the indicator will not be shown.- See Also:
-
INDICATOR_GRAVITY_STRETCH
public static final int INDICATOR_GRAVITY_STRETCHIndicator gravity used to stretch the tab selection indicator across the entire height of theTabLayout. This will disregardtabIndicatorHeightand the indicator drawable's intrinsic height, if set.- See Also:
-
INDICATOR_ANIMATION_MODE_LINEAR
public static final int INDICATOR_ANIMATION_MODE_LINEARIndicator animation mode used to translate the selected tab indicator between two tabs using a linear motion.The left and right side of the selection indicator translate in step over the duration of the animation. The only exception to this is when the indicator needs to change size to fit the width of its new destination tab's label.
- See Also:
-
INDICATOR_ANIMATION_MODE_ELASTIC
public static final int INDICATOR_ANIMATION_MODE_ELASTICIndicator animation mode used to translate the selected tab indicator by growing and then shrinking the indicator, making the indicator look like it is stretching while translating between destinations.The left and right side of the selection indicator translate out of step - with the right decelerating and the left accelerating (when moving right). This difference 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's width.
- See Also:
-
INDICATOR_ANIMATION_MODE_FADE
public static final int INDICATOR_ANIMATION_MODE_FADEIndicator animation mode used to switch the selected tab indicator from one tab to another by sequentially fading it out from the current destination and in at its new destination.- See Also:
-
-
Constructor Details
-
TabLayout
-
TabLayout
-
TabLayout
public TabLayout(@NonNull Context context, @Nullable AttributeSet attrs, @Nullable @AttrRes ResourceId defStyleAttr) -
TabLayout
public TabLayout(@NonNull Context context, @Nullable AttributeSet attrs, @Nullable @AttrRes ResourceId defStyleAttr, @Nullable @StyleRes ResourceId defStyleRes)
-
-
Method Details
-
setSelectedTabIndicatorColor
Sets the tab indicator's color for the currently selected tab.If the tab indicator color is not
Color.TRANSPARENT, the indicator will be wrapped and tinted right before it is drawn byView.draw(Canvas). If you'd like the inherent color or the tinted color of a custom drawable to be used, make sure this color is set toColor.TRANSPARENTto avoid your color/tint being overridden.- Parameters:
color- color to use for the indicator
-
setScrollPosition
public void setScrollPosition(int position, float positionOffset, boolean updateSelectedTabView) Set the scroll position of theTabLayout.- Parameters:
position- Position of the tab to scroll.positionOffset- Value from [0, 1) indicating the offset fromposition.updateSelectedTabView- Whether to draw the tab at the specified position + positionOffset as selected.Note that calling the method with
updateSelectedTabView = truedoes not select a tab at the specified position, but only draws it as selected. This can be useful for when the TabLayout behavior needs to be linked to another view, such asViewPager.- See Also:
-
setScrollPosition
public void setScrollPosition(int position, float positionOffset, boolean updateSelectedTabView, boolean updateIndicatorPosition) Set the scroll position of theTabLayout.- Parameters:
position- Position of the tab to scroll.positionOffset- Value from [0, 1) indicating the offset fromposition.updateSelectedTabView- Whether to draw the tab at the specified position + positionOffset as selected.Note that calling the method with
updateSelectedTabView = truedoes not select a tab at the specified position, but only draws it as selected. This can be useful for when the TabLayout behavior needs to be linked to another view, such asViewPager.updateIndicatorPosition- Whether to set the indicator to the specified position and offset.Note that calling the method with
updateIndicatorPosition = truedoes not select a tab at the specified position, but only updates the indicator position. This can be useful for when the TabLayout behavior needs to be linked to another view, such asViewPager.- See Also:
-
addTab
Add a tab to this layout. The tab will be added at the end of the list. If this is the first tab to be added it will become the selected tab.- Parameters:
tab- Tab to add
-
addTab
Add a tab to this layout. The tab will be inserted atposition. If this is the first tab to be added it will become the selected tab.- Parameters:
tab- The tab to addposition- The new position of the tab
-
addTab
Add a tab to this layout. The tab will be added at the end of the list.- Parameters:
tab- Tab to addsetSelected- True if the added tab should become the selected tab.
-
addTab
Add a tab to this layout. The tab will be inserted atposition.- Parameters:
tab- The tab to addposition- The new position of the tabsetSelected- True if the added tab should become the selected tab.
-
onInterceptTouchEvent
Description copied from class:ViewGroupImplement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.Using this function takes some care, as it has a fairly complicated interaction with
View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:- You will receive the down event here.
- The down event will be handled either by a child of this view group, or given to your own onTouchEvent() method to handle; this means you should implement onTouchEvent() to return true, so you will continue to see the rest of the gesture (instead of looking for a parent view to handle it). Also, by returning true from onTouchEvent(), you will not receive any following events in onInterceptTouchEvent() and all touch processing must happen in onTouchEvent() like normal.
- For as long as you return false from this function, each following event (up to and including the final up) will be delivered first here and then to the target's onTouchEvent().
- If you return true from here, you will not receive any
following events: the target view will receive the same event but
with the action
MotionEvent.ACTION_CANCEL, and all further events will be delivered to your onTouchEvent() method and no longer appear here.
- Overrides:
onInterceptTouchEventin classHorizontalScrollView- Parameters:
event- The motion event being dispatched down the hierarchy.- Returns:
- Return true to steal motion events from the children and have them dispatched to this ViewGroup through onTouchEvent(). The current target will receive an ACTION_CANCEL event, and no further messages will be delivered here.
-
onTouchEvent
Description copied from class:ViewImplement this method to handle touch screen motion events.If this method is used to detect click actions, it is recommended that the actions be performed by implementing and calling
View.performClick(). This will ensure consistent system behavior.- Overrides:
onTouchEventin classHorizontalScrollView- Parameters:
event- the touch event- Returns:
trueif the event was handled by the view,falseotherwise
-
addOnTabSelectedListener
Add aTabLayout.OnTabSelectedListenerthat will be invoked when tab selection changes.Components that add a listener should take care to remove it when finished via
removeOnTabSelectedListener(OnTabSelectedListener).- Parameters:
listener- listener to add
-
removeOnTabSelectedListener
Remove the givenTabLayout.OnTabSelectedListenerthat was previously added viaaddOnTabSelectedListener(OnTabSelectedListener).- Parameters:
listener- listener to remove
-
clearOnTabSelectedListeners
public void clearOnTabSelectedListeners()Remove all previously addedTabLayout.OnTabSelectedListeners. -
newTab
Create and return a newTabLayout.Tab. You need to manually add this usingaddTab(Tab)or a related method.- Returns:
- A new Tab
- See Also:
-
getTabCount
public int getTabCount()Returns the number of tabs currently registered with the tab layout.- Returns:
- Tab count
-
getTabAt
Returns the tab at the specified index. -
getSelectedTabPosition
public int getSelectedTabPosition()Returns the position of the current selected tab.- Returns:
- selected tab position, or
-1if there isn't a selected tab.
-
removeTab
Remove a tab from the layout. If the removed tab was selected it will be deselected and another tab will be selected if present.- Parameters:
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 another tab will be selected if present.- Parameters:
position- Position of the tab to remove
-
removeAllTabs
public void removeAllTabs()Remove all tabs from the tab layout and deselect the current tab. -
setTabMode
public void setTabMode(int mode) Set the behavior mode for the Tabs in this layout. The valid input options are:MODE_FIXED: Fixed tabs display all tabs concurrently and are best used with content that benefits from quick pivots between tabs.MODE_SCROLLABLE: Scrollable tabs display a subset of tabs at any given moment, and can contain 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 directly compare the tab labels. This mode is commonly used with aViewPager.
- Parameters:
mode- one ofMODE_FIXED,MODE_SCROLLABLEorMODE_AUTO.
-
getTabMode
public int getTabMode()Returns the current mode used by thisTabLayout.- See Also:
-
setTabGravity
public void setTabGravity(int gravity) Set the gravity to use when laying out the tabs.- Parameters:
gravity- one ofGRAVITY_CENTER,GRAVITY_FILLorGRAVITY_START.
-
getTabGravity
public int getTabGravity()The current gravity used for laying out tabs.- See Also:
-
setSelectedTabIndicatorGravity
public void setSelectedTabIndicatorGravity(int indicatorGravity) Set the indicator gravity used to align the tab selection indicator in theTabLayout. You must set the indicator height via the custom indicator drawable's intrinsic height (preferred). Otherwise, the indicator will not be shown unless gravity is set toINDICATOR_GRAVITY_STRETCH, in which case it will ignore indicator height and stretch across the entire height of theTabLayout. This defaults toINDICATOR_GRAVITY_BOTTOMif not set.- Parameters:
indicatorGravity- one ofINDICATOR_GRAVITY_BOTTOM,INDICATOR_GRAVITY_CENTER,INDICATOR_GRAVITY_TOP, orINDICATOR_GRAVITY_STRETCH
-
getTabIndicatorGravity
public int getTabIndicatorGravity()Get the current indicator gravity used to align the tab selection indicator in theTabLayout.- Returns:
- one of
INDICATOR_GRAVITY_BOTTOM,INDICATOR_GRAVITY_CENTER,INDICATOR_GRAVITY_TOP, orINDICATOR_GRAVITY_STRETCH
-
setTabIndicatorAnimationMode
public void setTabIndicatorAnimationMode(int tabIndicatorAnimationMode) Set the mode by which the selection indicator should animate when moving between destinations.Defaults to
INDICATOR_ANIMATION_MODE_LINEAR. Changing this is useful as a stylistic choice.- Parameters:
tabIndicatorAnimationMode- one ofINDICATOR_ANIMATION_MODE_LINEARorINDICATOR_ANIMATION_MODE_ELASTIC- See Also:
-
getTabIndicatorAnimationMode
public int getTabIndicatorAnimationMode()Get the current indicator animation mode used to animate the selection indicator between destinations.- Returns:
- one of
INDICATOR_ANIMATION_MODE_LINEARorINDICATOR_ANIMATION_MODE_ELASTIC - See Also:
-
setTabIndicatorFullWidth
public void setTabIndicatorFullWidth(boolean tabIndicatorFullWidth) Enable or disable option to fit the tab selection indicator to the full width of the tab item rather than to the tab item's content.Defaults to true. If set to false and the tab item has a text label, the selection 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 be 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 selection indicator width will be set to the minimum width value.
- Parameters:
tabIndicatorFullWidth- Whether or not to fit selection indicator width to full width of the tab item- See Also:
-
isTabIndicatorFullWidth
public boolean isTabIndicatorFullWidth()Get whether or not selection indicator width is fit to full width of the tab item, or fit to the tab item's content.- Returns:
- whether or not selection indicator width is fit to the full width of the tab item
- See Also:
-
setInlineLabel
public void setInlineLabel(boolean inline) Set whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.- See Also:
-
isInlineLabel
public boolean isInlineLabel()Returns whether tab labels will be displayed inline with tab icons, or if they will be displayed underneath tab icons.- See Also:
-
setUnboundedRipple
public void setUnboundedRipple(boolean unboundedRipple) Set whether thisTabLayoutwill have an unbounded ripple effect or if ripple will be bound to the tab item size.Defaults to false.
- See Also:
-
hasUnboundedRipple
public boolean hasUnboundedRipple()Returns whether thisTabLayouthas an unbounded ripple effect, or if ripple is bound to the tab item size.- See Also:
-
setTabTextColors
Sets the text colors for the different states (normal, selected) used for the tabs.- See Also:
-
getTabTextColors
Gets the text colors for the different states (normal, selected) used for the tabs. -
setTabTextColors
public void setTabTextColors(int normalColor, int selectedColor) Sets the text colors for the different states (normal, selected) used for the tabs. -
setTabIconTint
Sets the icon tint for the different states (normal, selected) used for the tabs.- See Also:
-
getTabIconTint
Gets the icon tint for the different states (normal, selected) used for the tabs. -
getTabRippleColor
Returns the ripple color for this TabLayout.- Returns:
- the color (or ColorStateList) used for the ripple
- See Also:
-
setTabRippleColor
Sets the ripple color for this TabLayout.When running on devices with KitKat, we draw this color as a filled overlay rather than a ripple.
- Parameters:
color- color (or ColorStateList) to use for the ripple- See Also:
-
getTabSelectedIndicator
Returns the selection indicator drawable for this TabLayout.- Returns:
- The drawable used as the tab selection indicator, if set.
- See Also:
-
setSelectedTabIndicator
Sets the selection indicator for this TabLayout. By default, this is a line along the bottom of the tab. IftabIndicatorColoris specified via the TabLayout's style or viasetSelectedTabIndicatorColor(int)the selection indicator will be tinted that color. Otherwise, it will use the colors specified in the drawable.Setting the indicator drawable to null will cause
TabLayoutto use the default,ShapeDrawableline indicator.- Parameters:
tabSelectedIndicator- A drawable to use as the selected tab indicator.- See Also:
-
setupWithViewPager
The one-stop shop for setting up thisTabLayoutwith aViewPager.This is the same as calling
setupWithViewPager(ViewPager, boolean)with auto-refresh enabled.- Parameters:
viewPager- the ViewPager to link to, ornullto clear any previous link
-
setupWithViewPager
The one-stop shop for setting up thisTabLayoutwith aViewPager.This method will link the given ViewPager and this TabLayout together so that changes in one are automatically reflected in the other. This includes scroll state changes and clicks. The tabs displayed in this layout will be populated from the ViewPager adapter's page titles.
If
autoRefreshistrue, any changes in thePagerAdapterwill trigger this layout to re-populate itself from the adapter's titles.If the given ViewPager is non-null, it needs to already have a
PagerAdapterset.- Parameters:
viewPager- the ViewPager to link to, ornullto clear any previous linkautoRefresh- whether this layout should refresh its contents if the given ViewPager's content changes
-
shouldDelayChildPressedState
public boolean shouldDelayChildPressedState()Description copied from class:ViewGroupReturn true if the pressed state should be delayed for children or descendants of this ViewGroup. Generally, this should be done for containers that can scroll, such as a List. This prevents the pressed state from appearing when the user is actually trying to scroll the content.The default implementation returns false. Subclasses that do scroll should override this method and return true.
- Overrides:
shouldDelayChildPressedStatein classHorizontalScrollView
-
onAttachedToWindow
protected void onAttachedToWindow()Description copied from class:ViewThis is called when the view is attached to a window. At this point it has a Surface and will start drawing. Note that this function is guaranteed to be called beforeView.onDraw(Canvas), however it may be called any time before the first onDraw -- including before or afterView.onMeasure(int, int).- Overrides:
onAttachedToWindowin classView- See Also:
-
onDetachedFromWindow
protected void onDetachedFromWindow()Description copied from class:ViewThis is called when the view is detached from a window. At this point it no longer has a surface for drawing.- Overrides:
onDetachedFromWindowin classView- See Also:
-
addView
Description copied from class:ViewGroupAdds a child view. If no layout parameters are already set on the child, the default parameters for this ViewGroup are set on the child.
Note: do not invoke this method from
View.draw(Canvas),View.onDraw(Canvas),ViewGroup.dispatchDraw(Canvas)or any related method.- Overrides:
addViewin classHorizontalScrollView- Parameters:
child- the child view to add- See Also:
-
addView
Description copied from class:ViewGroupAdds a child view. If no layout parameters are already set on the child, the default parameters for this ViewGroup are set on the child.Note: do not invoke this method from
View.draw(Canvas),View.onDraw(Canvas),ViewGroup.dispatchDraw(Canvas)or any related method.- Overrides:
addViewin classHorizontalScrollView- Parameters:
child- the child view to addindex- the position at which to add the child- See Also:
-
addView
Description copied from class:ViewGroupAdds a child view with the specified layout parameters.Note: do not invoke this method from
View.draw(Canvas),View.onDraw(Canvas),ViewGroup.dispatchDraw(Canvas)or any related method.- Specified by:
addViewin interfaceViewManager- Overrides:
addViewin classHorizontalScrollView- Parameters:
child- the child view to addparams- the layout parameters to set on the child
-
addView
Description copied from class:ViewGroupAdds a child view with the specified layout parameters.Note: do not invoke this method from
View.draw(Canvas),View.onDraw(Canvas),ViewGroup.dispatchDraw(Canvas)or any related method.- Overrides:
addViewin classHorizontalScrollView- Parameters:
child- the child view to addindex- the position at which to add the child or -1 to add lastparams- the layout parameters to set on the child
-
onDraw
Description copied from class:ViewDraw the content of this view, implement this to do your drawing.Note that (0, 0) will be the top left of the bounds, and (width, height) will be the bottom right of the bounds.
-
onMeasure
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) Description copied from class:ViewMeasure the view and its content to determine the measured width and the measured height. This method is invoked byView.measure(int, int)and should be overridden by subclasses to provide accurate and efficient measurement of their contents.CONTRACT: When overriding this method, you must call
View.setMeasuredDimension(int, int)to store the measured width and height of this view. Failure to do so will trigger anIllegalStateException, thrown byView.measure(int, int). Calling super.onMeasure() is a valid use.The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override the base one to provide better measurements of their content.
- Overrides:
onMeasurein classHorizontalScrollView- Parameters:
widthMeasureSpec- width measure specification imposed by the parentMeasureSpecheightMeasureSpec- height measure specification imposed by the parentMeasureSpec
-
selectTab
Selects the given tab.- Parameters:
tab- The tab to select, ornullto select none.- See Also:
-
selectTab
Selects the given tab. Will always animate to the selected tab if the current tab is reselected, regardless of the value ofupdateIndicator.- Parameters:
tab- The tab to select, ornullto select none.updateIndicator- Whether to update the indicator.- See Also:
-