我有一个字体,我想更改 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>
然后只需使用下面的注释以编程方式添加任何样式。
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
TextView mTitle = (TextView) toolbar.findViewById(R.id.title);
OR
改变使用风格。需要一个信息点击这里.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)