【Android】SpannableStringBuilder在PagerTabStrip 中添加图标
开始解说::::::::::::::
view.PagerTabStrip组件的方法是
public CharSequence getPageTitle(int position) { }
public CharSequence getPageTitle(int position) { SpannableStringBuilder ssb = new SpannableStringBuilder(" " + tabs[position]); switch (position){ case 0 : Drawable mydrawable = getResources().getDrawable(R.drawable.main_course_icon); mydrawable.setBounds(0, 0, mydrawable.getIntrinsicWidth(), mydrawable.getIntrinsicHeight()); ImageSpan span = new ImageSpan(mydrawable, ImageSpan.ALIGN_BASELINE); ssb.setSpan(span, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); break; case 1 : Drawable myexer = getResources().getDrawable(R.drawable.main_exercises_icon); myexer.setBounds(0, 0, myexer.getIntrinsicWidth(), myexer.getIntrinsicHeight()); ImageSpan span2 = new ImageSpan(myexer, ImageSpan.ALIGN_BASELINE); ssb.setSpan(span2, 1, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE); break; case 2 : Drawable my_icon= getResources().getDrawable(R.drawable.main_my_icon); my_icon.setBounds(0, 0, my_icon.getIntrinsicWidth(), my_icon.getIntrinsicHeight()); ImageSpan span3 = new ImageSpan(my_icon, ImageSpan.ALIGN_BASELINE); ssb.setSpan(span3, 1, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE); break; } // ssb.setSpan(new RelativeSizeSpan(1.2f), 1, ssb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return ssb; }