TabHost和FontAwesome图标

时间:2015-03-06 19:44:46

标签: java android fonts

如何将字体真棒图标返回到tabhost的标题选项卡?现在它没有显示任何内容.....我的方法下面适用于PagerTabStrip的差异是什么?

    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/fontawesome-webfont.ttf");
    // create the TabHost that will contain the Tabs
    TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
    TabHost.TabSpec tab1 = tabHost.newTabSpec("tab1");

    //this wont show the icon, it's blank:
    tab1.setIndicator(icon_giver(font,  "\uf0c0"));




//my method is:

public CharSequence icon_giver(Typeface font, String icon_id){
    String title_of_page = "";
    SpannableStringBuilder styled;
    title_of_page = icon_id;
    styled = new SpannableStringBuilder(title_of_page);
    styled.setSpan(new CustomTypefaceSpan("", font), 0, title_of_page.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
    return styled;
}

1 个答案:

答案 0 :(得分:0)

好的,所以我必须这样做:

github上的

TextDrawable项目。您可以对其进行修改,以便将Font-Awesome用作字体。

我使用以下方法应用它:

TextDrawable draw_icon = new TextDrawable(this);
draw_icon.setText(icon_giver(font, "\uf0c0"));
tab1.setIndicator("",draw_icon);