public class SlidingTabLayout
extends HorizontalScrollView
Activity
or Fragment
call
setViewPager(ViewPager)
providing it the ViewPager this layout is being used for.
The colors can be customized in two ways. The first and simplest is to provide an array of colors
via setSelectedIndicatorColors(int...)
. The
alternative is via the SlidingTabLayout.TabColorizer
interface which provides you complete control over
which color is used for any individual position.
The views used as tabs can be customized by calling setCustomTabView(int, int)
,
providing the layout ID of your custom layout.Modifier and Type | Class and Description |
---|---|
private class |
SlidingTabLayout.InternalViewPagerListener |
private class |
SlidingTabLayout.TabClickListener |
static interface |
SlidingTabLayout.TabColorizer
Allows complete control over the colors drawn in the tab layout.
|
Modifier and Type | Field and Description |
---|---|
private <any> |
mContentDescriptions |
private boolean |
mDistributeEvenly |
private SlidingTabStrip |
mTabStrip |
private int |
mTabViewLayoutId |
private int |
mTabViewTextViewId |
private int |
mTitleOffset |
private android.support.v4.view.ViewPager |
mViewPager |
private android.support.v4.view.ViewPager.OnPageChangeListener |
mViewPagerPageChangeListener |
private static int |
TAB_VIEW_PADDING_DIPS |
private static int |
TAB_VIEW_TEXT_SIZE_SP |
private static int |
TITLE_OFFSET_DIPS |
Constructor and Description |
---|
SlidingTabLayout(Context context) |
SlidingTabLayout(Context context,
AttributeSet attrs) |
SlidingTabLayout(Context context,
AttributeSet attrs,
int defStyle) |
Modifier and Type | Method and Description |
---|---|
protected TextView |
createDefaultTabView(Context context)
Create a default view to be used for tabs.
|
protected void |
onAttachedToWindow() |
private void |
populateTabStrip() |
private void |
scrollToTab(int tabIndex,
int positionOffset) |
void |
setContentDescription(int i,
java.lang.String desc) |
void |
setCustomTabColorizer(SlidingTabLayout.TabColorizer tabColorizer)
Set the custom
SlidingTabLayout.TabColorizer to be used. |
void |
setCustomTabView(int layoutResId,
int textViewId)
Set the custom layout to be inflated for the tab views.
|
void |
setDistributeEvenly(boolean distributeEvenly) |
void |
setOnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener listener)
Set the
ViewPager.OnPageChangeListener . |
void |
setSelectedIndicatorColors(int... colors)
Sets the colors to be used for indicating the selected tab.
|
void |
setViewPager(android.support.v4.view.ViewPager viewPager)
Sets the associated view pager.
|
private static final int TITLE_OFFSET_DIPS
private static final int TAB_VIEW_PADDING_DIPS
private static final int TAB_VIEW_TEXT_SIZE_SP
private int mTitleOffset
private int mTabViewLayoutId
private int mTabViewTextViewId
private boolean mDistributeEvenly
private android.support.v4.view.ViewPager mViewPager
private <any> mContentDescriptions
private android.support.v4.view.ViewPager.OnPageChangeListener mViewPagerPageChangeListener
private final SlidingTabStrip mTabStrip
public SlidingTabLayout(Context context)
public SlidingTabLayout(Context context, AttributeSet attrs)
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle)
public void setCustomTabColorizer(SlidingTabLayout.TabColorizer tabColorizer)
SlidingTabLayout.TabColorizer
to be used.
If you only require simple custmisation then you can use
setSelectedIndicatorColors(int...)
to achieve
similar effects.public void setDistributeEvenly(boolean distributeEvenly)
public void setSelectedIndicatorColors(int... colors)
public void setOnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener listener)
ViewPager.OnPageChangeListener
. When using SlidingTabLayout
you are
required to set any ViewPager.OnPageChangeListener
through this method. This is so
that the layout can update it's scroll position correctly.ViewPager.setOnPageChangeListener(ViewPager.OnPageChangeListener)
public void setCustomTabView(int layoutResId, int textViewId)
layoutResId
- Layout id to be inflatedtextViewId
- id of the TextView
in the inflated viewpublic void setViewPager(android.support.v4.view.ViewPager viewPager)
protected TextView createDefaultTabView(Context context)
setCustomTabView(int, int)
.private void populateTabStrip()
public void setContentDescription(int i, java.lang.String desc)
protected void onAttachedToWindow()
private void scrollToTab(int tabIndex, int positionOffset)