机器人:如何从Android支持库4版图标/可绘制添加到PagerTabStrip? [英] android: How to add icons/drawables to the PagerTabStrip from the Android Support Lib version 4?

查看:139
本文介绍了机器人:如何从Android支持库4版图标/可绘制添加到PagerTabStrip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安卓?如何图标/可绘制从Android支持库4版本添加到PagerTabStrip

android: How to add icons/drawables to the PagerTabStrip from the Android Support Lib version 4 ?

这是非常具体的问题的人意识到PagerTabStrip的,我无法找到足够的例子在任何地方,它以某种方式新的(该PagerTabStrip),所以我无法找到足够的信息。

This is very specific question to people aware of the PagerTabStrip, I couldn't find enough examples anywhere, it's somehow new (The PagerTabStrip) so i couldn't find enough info.

推荐答案

您可以轻松地使用SpannableString或SpannableStringBuilder添加一个图标/绘制到PageTabStrip。

You can easily add an 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, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 

    return sb;
}

这篇关于机器人:如何从Android支持库4版图标/可绘制添加到PagerTabStrip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆