【发布时间】:2014-05-15 09:37:59
【问题描述】:
我的问题是我想更改操作栏的字体,而不是像实现文本视图那样为操作栏进行自定义布局,然后在该文本视图上应用字体,因为我想要字幕栏文本,那么解决方案是什么
【问题讨论】:
-
你想只改变标题的字体吗?
-
我也想在标题和副标题上设置字体..
标签: android android-custom-view android-actionbar-compat
我的问题是我想更改操作栏的字体,而不是像实现文本视图那样为操作栏进行自定义布局,然后在该文本视图上应用字体,因为我想要字幕栏文本,那么解决方案是什么
【问题讨论】:
标签: android android-custom-view android-actionbar-compat
您可以将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);
【讨论】:
你可以这样做
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);
【讨论】:
assets 文件夹中
在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")));
希望对你有帮助
【讨论】:
getResources().getIdentifier("action_bar_title", "id", "android") 是一种不好的做法。
action_bar_title 是一个私有ID。
SpannableString)而不是字符串。它适用于 setTitle 和 setSubtitle。