She*_*bic 25 android android-layout android-viewpager android-tabs
android:如何从Android Support Lib版本4向PagerTabStrip添加图标/ drawable?
对于知道PagerTabStrip的人来说,这是一个非常具体的问题,我在任何地方都找不到足够的例子,它是新的(The PagerTabStrip)所以我找不到足够的信息.
Ste*_*veR 53
您可以使用SpannableString或SpannableStringBuilder轻松地向PageTabStrip添加图标/绘图.
例如,要在文本之前显示图标:
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, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15474 次 |
| 最近记录: |