2014-10-28 136 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