2014-10-28 56 views
0

我们如何自定义动作条标题的字体样式。字体的样式也是自定义的,必须导入到应用程序中?Android:如何自定义字体样式到动作栏标题

+1

可能重复[如何设置自定义字体在ActionBar标题?](http://stackoverflow.com/questions/8607707/how-to-set-a-cu stom-font-in-the-actionbar-title) – 2Dee 2014-10-28 08:50:53

+0

顺便说一句,我发现在Google中重复键入“自定义字体操作栏”。我仍然想知道你怎么没有... – 2Dee 2014-10-28 08:56:22

回答

8

试试这个:

SpannableString s = new SpannableString("My Title"); 
    s.setSpan(new TypefaceSpan(this, "MyTypeface.otf"), 0, s.length(), 
      Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); 

    // Update the action bar title with the TypefaceSpan instance 
    ActionBar actionBar = getActionBar(); 
    actionBar.setTitle(s); 

希望它可以帮助

Reference

UPD:定制TypefaceSpan的源代码是here