改变在Android上的应用程序标题的字体 [英] Changing the font of the application title in android

查看:633
本文介绍了改变在Android上的应用程序标题的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字体,我想改变的动作栏标题的字体在Android的。 有没有一种方法来设置这样的标题字体?

I have a typeface, I want to change the font of the action-bar title in android. Is there a way to set title typeface like that?

this.setTitle(myTitle.toUpperCase()); 
this.setTypefaceofTitle(tf);

这是不是复制的问题,这个环节对这些方法(<一href="http://stackoverflow.com/questions/8607707/how-to-set-a-custom-font-in-the-actionbar-title">How在动作条标题设置自定义字体?)不工作。 当我尝试它们,日食给出了错误: java.lang.noSuchMethodError

this is not a copy question, those methods on this link (How to Set a Custom Font in the ActionBar Title?) are not working. When I try them, eclipse gives that error : java.lang.noSuchMethodError

推荐答案

试试这个,

    int actionBarTitle = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
TextView actionBarTitleView = (TextView) getWindow().findViewById(actionBarTitle);
Typeface robotoBoldCondensedItalic = Typeface.createFromAsset(getAssets(), "fonts/Roboto-BoldCondensedItalic.ttf");
if(actionBarTitleView != null){
    actionBarTitleView.setTypeface(robotoBoldCondensedItalic);
}

如果它的工具栏意味着尝试像如下图所示。

If it's toolbar means try like as below.

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="@color/action_color"
app:theme="@style/ToolBarTheme" >


 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Title"
    android:layout_gravity="center"
    android:id="@+id/title_txt" />


</android.support.v7.widget.Toolbar>

然后,只需通过编程方式使用下面的评论添加任何风格。

Then just add any style via programmatically using below comment.

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView mTitle = (TextView) toolbar.findViewById(R.id.title);

使用样式更改。需求的一个信息点击此处

Change using style. Need one info click here.

这篇关于改变在Android上的应用程序标题的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆