有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java TabHost和Fonthouse图标

如何将字体图标返回到tabhost的标题选项卡?现在它什么也没显示。。。。。我下面的方法适用于PagerTaskTrip有什么区别

    Typeface font = Typeface.createFromAsset(getAssets(), "fonts/fontawesome-webfont.ttf");
    // create the TabHost that will contain the Tabs
    TabHost tabHost = (TabHost)findViewById(安卓.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) 个答案

  1. # 1 楼答案

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

    github上的TextDrawable项目。您可以对其进行修改,使字体用作字体

    我通过以下方式应用它:

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