【发布时间】:2017-04-26 19:25:56
【问题描述】:
我想更改我的 ActionBar 标题的字体。我找到了很多关于此搜索的结果(example1、example2、example3、example4),但任何结果都可以解决我的问题。
我想更改没有任何可以调用的 TextView 项的默认 ActionBar 的字体并修改字体。我知道我可以创建自定义 ActionBar,但我想尝试在没有自定义 ActionBar 的情况下执行此操作。
这是我的代码:
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
...
main1.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/mapa"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
ActionBar 结果:
我能做什么?
谢谢大家。
【问题讨论】:
-
如果你想改变 Action bar 的标题,只需在你的 Activity
getActionBar().setTitle("Action Bar Title");的 onCreate() 中提供以下 1 行代码,以防你使用支持库。使用:getSupportActionBar().setTitle("Action Bar Title");跨度> -
我不想改变标题而是标题的字体
-
stackoverflow.com/a/15181195/5829494 看看这个可能对你有帮助。我试过了,它有效。只需将字体放在 main/assets/fonts 中即可
-
当我应用最后一个解决方案时,出现错误 Cannot resolve contructor 'TypefaceSpan(MainActivity, java.lang.string) in this part
s.setSpan(new TypefaceSpan(this, "Yanone.ttf"), 0, s.length()。我能做什么? -
你已经关闭了
TypefaceSpan类,对吧?