0
A
回答
0
这里是你寻找答案:
public boolean onCreateOptionsMenu(android.view.Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.cool_menu, menu);
getLayoutInflater().setFactory(new Factory() {
public View onCreateView(String name, Context context,
AttributeSet attrs) {
if (name.equalsIgnoreCase(
"com.android.internal.view.menu.IconMenuItemView")) {
try {
LayoutInflater li = LayoutInflater.from(context);
final View view = li.createView(name, null, attrs);
new Handler().post(new Runnable() {
public void run() {
// set the background drawable if you want that
//or keep it default -- either an image, border
//gradient, drawable, etc.
view.setBackgroundResource(R.drawable.myimage);
((TextView) view).setTextSize(20);
// set the text color
Typeface face = Typeface.createFromAsset(
getAssets(),"OldeEnglish.ttf");
((TextView) view).setTypeface(face);
((TextView) view).setTextColor(Color.RED);
}
});
return view;
} catch (InflateException e) {
//Handle any inflation exception here
} catch (ClassNotFoundException e) {
//Handle any ClassNotFoundException here
}
}
return null;
}
});
return super.onCreateOptionsMenu(menu);
}
来源:https://stackoverflow.com/a/11376591/5250273
但是,如果你想有一个简单的解决方案,你应该看看这个库:https://github.com/chrisjenx/Calligraphy
+0
它像ActivityBar上的魅力一样工作,但它在工具栏上不起作用。任何想法? –
+0
如果您的工具栏包含TextView等视图,请尝试使用我在帖子中共享的书法库更改它们的字体。 –
+0
图书馆工作...谢谢 –
相关问题
- 1. 溢出菜单更改自定义工具栏布局
- 2. sapUI5溢出工具栏
- 3. 自定义markitUp工具栏
- 4. WPF自定义工具栏
- 5. SSMS工具栏自定义
- 6. 自定义WYSIHTML5工具栏
- 7. CKEditor定义自定义工具栏
- 8. 在android的工具栏上的自定义字体
- 9. UINavigation栏自定义字体
- 10. 工具栏不显示溢出菜单
- 11. 工具栏不显示溢出图标
- 12. WPF中的可自定义工具栏
- 13. CKEditor自定义工具栏配置
- 14. 自定义工具栏问题
- 15. 自定义材质设计工具栏
- 16. 自定义sencha触摸工具栏
- 17. 带图像的自定义工具栏
- 18. 如何自定义XCode工具栏?
- 19. 自定义ITHIT AjaxFilebrowser工具栏
- 20. 自定义工具栏重叠片段
- 21. RibbonGroup'自定义工具栏'OfficeID?
- 22. 自定义工具栏设计
- 23. Firefox自定义工具栏按钮
- 24. 如何自定义ckeditor的工具栏
- 25. 自定义工具栏的Android
- 26. CKEditor的多个自定义工具栏
- 27. 自定义工具栏Kendo Grid
- 28. 无法自定义django-ckeditor工具栏
- 29. CKEditor自定义工具栏WITH config.extraPlugins
- 30. 更改自定义工具栏文本
可能重复检查这个[link](http://stackoverflow.com/questions/4135699/how-to-set-a-font-for-the-options-menu) –
[Android toolbar中心标题和自定义字体](http ://stackoverflow.com/questions/26533510/android-toolbar -center-title-and-custom-font) –