2015-12-29 43 views
0

在我研究的过程中,我发现了一个很好的解决方案,使用TypefaceSpan在ActionBar标题字体中设置自定义字体。事实上,这是第二个也是投票最多的答案here。该代码看起来是这样的:使用TypefaceSpan设置ActionBar标题字体

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); 

看起来不错,但所谓的TypefaceSpan本例中使用不再exisits构造函数中,检查this,只有两个构造函数为:

public TypefaceSpan(String family) 

public TypefaceSpan(Parcel src) 

我还可以使用新的构造函数来设置新的构造函数的ActionBar标题字体吗?或者我必须转向一种新方法?

回答

0

实际上,构造函数来自自定义的TypefaceSpan类。 您可以将public class TypefaceSpan extends MetricAffectingSpan类从答案(在第二个框中)复制到您的类中,并将其用作构造函数。

相关问题