PagerSlidingTabStrip 改变指示器的颜色
PagerSlidingTabStrip Changing colour of the indicator
您好,我正在使用 PagerSlidingTabStrip 在 viewpager 中显示标签。当用户从第一个片段滑动到第二个片段时,我必须将指示器的颜色从红色更改为绿色。颜色的过渡必须是平滑的。但我无法决定我该怎么做。请帮忙 !!!
提前致谢!!!
打开您的 PagerSlidingTabStrip 库 class 您将得到这些代码行
private int indicatorColor = 0xFF666666;
private int underlineColor = 0x1A000000;
否则,您可以通过编程方式执行此操作
tabs.setIndicatorColor(indicatorColor)
改变那些颜色值你会得到你想要的。
试试这个!
int NTABS = 2;
int[] COLORS = { 0xFFFF0000, 0xFF00FF00 }; // COLORS.length == NTABS
mPagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
mPagerSlidingTabStrip.setIndicatorColor(getNewColor(position, positionOffset));
}
@Override public void onPageSelected(int position) {
}
@Override public void onPageScrollStateChanged(int state) {
}
});
private int getNewColor(int position, float offset) {
int next;
if (offset > 0) next = (position < NTABS) ? position+1 : position;
else next = (position > 0) ? position-1 : 0;
return blendColors(COLORS[next], COLORS[position], offset);
}
public int blendColors(int color1, int color2, float ratio) {
final float inverseRation = 1f - ratio;
float a = (Color.alpha(color1) * ratio) + (Color.alpha(color2) * inverseRation);
float r = (Color.red (color1) * ratio) + (Color.red (color2) * inverseRation);
float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
float b = (Color.blue (color1) * ratio) + (Color.blue (color2) * inverseRation);
return Color.argb((int) a, (int) r, (int) g, (int) b);
}
您好,我正在使用 PagerSlidingTabStrip 在 viewpager 中显示标签。当用户从第一个片段滑动到第二个片段时,我必须将指示器的颜色从红色更改为绿色。颜色的过渡必须是平滑的。但我无法决定我该怎么做。请帮忙 !!! 提前致谢!!!
打开您的 PagerSlidingTabStrip 库 class 您将得到这些代码行
private int indicatorColor = 0xFF666666;
private int underlineColor = 0x1A000000;
否则,您可以通过编程方式执行此操作
tabs.setIndicatorColor(indicatorColor)
改变那些颜色值你会得到你想要的。
试试这个!
int NTABS = 2;
int[] COLORS = { 0xFFFF0000, 0xFF00FF00 }; // COLORS.length == NTABS
mPagerSlidingTabStrip.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
mPagerSlidingTabStrip.setIndicatorColor(getNewColor(position, positionOffset));
}
@Override public void onPageSelected(int position) {
}
@Override public void onPageScrollStateChanged(int state) {
}
});
private int getNewColor(int position, float offset) {
int next;
if (offset > 0) next = (position < NTABS) ? position+1 : position;
else next = (position > 0) ? position-1 : 0;
return blendColors(COLORS[next], COLORS[position], offset);
}
public int blendColors(int color1, int color2, float ratio) {
final float inverseRation = 1f - ratio;
float a = (Color.alpha(color1) * ratio) + (Color.alpha(color2) * inverseRation);
float r = (Color.red (color1) * ratio) + (Color.red (color2) * inverseRation);
float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
float b = (Color.blue (color1) * ratio) + (Color.blue (color2) * inverseRation);
return Color.argb((int) a, (int) r, (int) g, (int) b);
}