PagerSlidingTabStrip 高亮选中标题

1、选中标题后,高亮标题
@Override
public void onPageSelected(int position) {
setSelectTextColor(position);
if (delegatePageListener != null) {
delegatePageListener.onPageSelected(position);
}
}
private void setSelectTextColor(int position) {
for (int i = ; i < tabCount; i++) {
View view = tabsContainer.getChildAt(i);
if (view instanceof ImageButton) {
} else if (view instanceof RelativeLayout) {
View viewText = ((RelativeLayout) view).getChildAt();
TextView tabTextView = (TextView) viewText;
if (viewText instanceof TextView) {
if (position == i) {
tabTextView.setTextColor(自定义颜色);
} else {
tabTextView.setTextColor(tabTextColor);
}
}
}
}
}

2、首次进入默认第一个标题高亮,关键标红代码

    private void updateTabStyles() {

        for (int i = ; i < tabCount; i++) {

            View v = tabsContainer.getChildAt(i);

            v.setBackgroundResource(tabBackgroundResId);

            if (v instanceof RelativeLayout) {
View v1 = ((RelativeLayout) v).getChildAt();
if (v1 instanceof TextView) { TextView tab = (TextView) v1;
tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
tab.setTypeface(tabTypeface, tabTypefaceStyle);
if (i == 0) {
tab.setTextColor(自定义颜色);
} else {
tab.setTextColor(tabTextColor);
} if (textAllCaps) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
tab.setAllCaps(true);
} else {
tab.setText(tab.getText().toString().toUpperCase(locale));
}
}
}
}
}
}
上一篇:用JS实现控制浏览器F12与右键功能


下一篇:Uoj #131. 【NOI2015】品酒大会 后缀数组,并查集