在Android中更改应用程序标题的字体 [英] Changing the font of the application title in android
本文介绍了在Android中更改应用程序标题的字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法设置这样的标题字体?
this.setTitle(myTitle.toUpperCase());
this.setTypefaceofTitle(tf);
这不是一个复制问题,这个链接上的这些方法(如何在ActionBar标题中设置自定义字体?)不起作用。
当我尝试它们时,eclipse会给出错误: 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);
}
如果它的工具栏意味着尝试如下。
< 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>
然后通过编程方式添加任何风格,使用以下注释。
工具栏工具栏=(工具栏)findViewById(R.id.toolbar);
TextView mTitle =(TextView)toolbar.findViewById(R.id.title);
或
使用样式更改。需要一个信息点击此处。
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);
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
解决方案
Try this,
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);
OR
Change using style. Need one info click here.
这篇关于在Android中更改应用程序标题的字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文