我正在使用带有PagerTitleStrip的网页浏览器,我想要的标题是这样的(取自htc):
目前我设法改变专注/非专注标题的文字颜色:
private CharSequence relativeSizeSpan(CharSequence source, int pos) {
final SpannableString ss = new SpannableString(source);
if (viewPager.getCurrentItem() != pos) {
ss.setSpan(new ForegroundColorSpan(0xffa8a5a5), 0, source.length(), 0);
}
else {
ss.setSpan(new ForegroundColorSpan(0xff787777), 0, source.length(), 0);
}
return ss;
}
答案 0 :(得分:0)
下面的内容可能有所帮助。尝试结合你的建议。
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
SpannableStringBuilder sb1 = new SpannableStringBuilder(" " + str1 + (position + 1)); // space added before text for convenience
sb1= coloredSpannable(sb1, position);
drw1.setBounds(0, 0, drw1.getIntrinsicWidth(), drw1.getIntrinsicHeight());
ImageSpan span1 = new ImageSpan(drw1, ImageSpan.ALIGN_BASELINE);
sb1.setSpan(span1, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb1;
case 1:
SpannableStringBuilder sb2 = new SpannableStringBuilder(" " + str2 + (position + 1)); // space added before text for convenience
sb2= coloredSpannable(sb2, position);
drw1.setBounds(0, 0, drw1.getIntrinsicWidth(), drw1.getIntrinsicHeight());
ImageSpan span2 = new ImageSpan(drw1, ImageSpan.ALIGN_BASELINE);
sb2.setSpan(span2, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb2;
case 2:
SpannableStringBuilder sb3 = new SpannableStringBuilder(" " + str3 + (position + 1)); // space added before text for convenience
sb3= coloredSpannable(sb3, position);
drw1.setBounds(0, 0, drw1.getIntrinsicWidth(), drw1.getIntrinsicHeight());
ImageSpan span3 = new ImageSpan(drw1, ImageSpan.ALIGN_BASELINE);
sb3.setSpan(span3, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb3;
default:
return null;
}
}
private SpannableStringBuilder coloredSpannable(SpannableStringBuilder source, int pos) {
final SpannableStringBuilder ss = source;
if (vpPager.getCurrentItem() > pos) {
ss.setSpan(new ForegroundColorSpan(Color.BLACK), 4, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else {
}
if (vpPager.getCurrentItem() < pos) {
ss.setSpan(new ForegroundColorSpan(Color.BLACK), 1, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
else {
}
return ss;
}