I used title in ViewPager like on the screen below : just a text with a android.support.v4.view.PagerTabStrip
in OnPageChangeListener()
I use method public CharSequence getPageTitle(int position)
and it sets title
is there any way to customize that field to look like this :
may be some kind of custom adapter for title?
You can easily add a icon/drawable to the PageTabStrip using SpannableString or SpannableStringBuilder.
For example, to display an icon before the text :
Drawable myDrawable; //Drawable you want to display
@Override
public CharSequence getPageTitle(int position) {
SpannableStringBuilder sb = new SpannableStringBuilder(" " + "Page #"+ position); // space added before text for convenience
myDrawable.setBounds(0, 0, myDrawable.getIntrinsicWidth(), myDrawable.getIntrinsicHeight());
ImageSpan span = new ImageSpan(myDrawable, ImageSpan.ALIGN_BASELINE);
sb.setSpan(span, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With