更改默认ActionBar的字体

时间:2017-04-26 19:25:57

标签: android android-actionbar

我想更改ActionBar标题的字体。我发现了很多关于此搜索的结果(example1example2example3example4),但是任何结果都解决了我的问题。

我想更改默认ActionBar的字体,它没有任何可以调用的TextView项并修改字体。我知道我有可能创建自定义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结果:

enter image description here

我该怎么办?

谢谢大家。

1 个答案:

答案 0 :(得分:1)

要更改textview的字体,您可以使用Calligraphy library

如果要在没有自定义视图的情况下更改ActionBar外观,可以使用样式。对于AppTheme,您可以设置自定义actionBarStyle。

    <style name="MyCustomActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:titleTextStyle">@style/MyCustomTextStyleWithFont</item>
    </style>