android操作栏中的自定义字体,无需自定义Actionbar

时间:2014-05-15 09:38:00

标签: android android-custom-view android-actionbar-compat

我的问题是我想更改操作栏的字体而不为操作栏设置自定义布局,例如implment文本视图,然后在该文本视图上应用字体,因为我想要字幕栏文本,所以它是什么解决方案

3 个答案:

答案 0 :(得分:1)

您可以将SpannableString与自定义TypeFaceSpan(https://stackoverflow.com/a/4826885/1785133)一起用于actionBar标题和副标题。

SpannableString sbTitle = new SpannableString(getTitle());
Typeface typeface = Typeface.createFromAsset(getAssets(), "custom.ttf"); //cache it
sbTitle.setSpan(new CustomTypefaceSpan("custom", typeface), 0, sbTitle.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
getActionBar().setTitle(sbTitle);

答案 1 :(得分:0)

您可以执行类似

的操作
SpannableString localSpannableString = new SpannableString("Penguin");
localSpannableString.setSpan(new TypefaceSpan(MainActivity.this, "PreludeFLF-BoldItalic.ttf"), 0, localSpannableString.length(), 33);

ActionBar localActionBar = getSupportActionBar();
localActionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#81D2F0")));
localActionBar.setTitle(localSpannableString);

答案 2 :(得分:-1)

onCreate()

中尝试以下代码
int titleId = getResources().getIdentifier("action_bar_title", "id",
            "android");
    TextView txtTitle = (TextView) findViewById(titleId);
    txtTitle.setTextColor(getResources().getColor(R.color.title_color));
    txtTitle.setTypeface((Typeface.createFromAsset(this.getAssets(),"FuturaBoldBT.ttf")));

希望这有帮助