设置字体菜单项actionBar appcompat v7

时间:2014-04-15 10:15:05

标签: android-actionbar typeface android-appcompat

我想更改acrionBar上的项目菜单的字体。

我正在使用appcompat v7 lib在Android版本低于11的设备上使用ActionBar。

如果我在' onCreateOptionsMenu()'中使用SpannableString更改字体,它可以正常工作,但在许多设备中,当您点击项目时应用程序崩溃。

SpannableString s = new SpannableString(item.getTitle());
s.setSpan(new GTypefaceSpan(context, typefaceName), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
item.setTitle(s);

' GTypefaceSpan'是一个自定义类来设置字体(它的工作原理)。

我尝试使用TextView而不是项目(类似于此伪代码):

TextView tVItem1 = (TextView) findViewById(R.id.item1);
tVItem1.set...
MenuItemCompat.setActionView(null, tVItem1);

但它直接崩溃了应用程序。

0 个答案:

没有答案