如何将自定义字体添加到操作栏?

时间:2015-09-18 10:41:16

标签: android fonts android-actionbar android-appbarlayout

我想知道如何将自己的自定义字体添加到android studio的操作栏中显示的应用名称。

2 个答案:

答案 0 :(得分:1)

您可以在ActionBar中设置CustomLayout

this.getActionBar().setDisplayShowCustomEnabled(true);
this.getActionBar().setDisplayShowTitleEnabled(false);

LayoutInflater inflator = LayoutInflater.from(this);
View v = inflator.inflate(R.layout.titleview, null);

//if you need to customize anything else about the text, do it here.
//I'm using a custom TextView with a custom font in my layout xml so all I need to do is set title
((TextView)v.findViewById(R.id.title)).setText(this.getTitle());

//assign the view to the actionbar
this.getActionBar().setCustomView(v);

您可以使用setTypeFace()

将自定义字体指定给textview

答案 1 :(得分:0)

我这样做是通过使用自定义字体制作应用名称的图像,然后在操作栏中将图像显示为徽标。更简单。

actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setLogo(R.drawable.app_logo);
相关问题