3

I want to change the font of my ActionBar title. I have found a lot of result (example1, example2, example3, example4) about this search but any solves my problem.

I want change the font of default ActionBar which don't have any TextView item that can be called and modify the font. I know I have the posibility to create a custom ActionBar, but I want to try to do this without custom ActionBar.

This is my code:

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 result:

enter image description here

What can I do?

Thanks for all.

Community
  • 1
  • 1

1 Answers1

1

To change textview's font you can use Calligraphy library

If you want to change ActionBar appearance without custom view you can use styles. For AppTheme you can set custom actionBarStyle.

    <style name="MyCustomActionBarStyle" parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:titleTextStyle">@style/MyCustomTextStyleWithFont</item>
    </style>
garmax1
  • 898
  • 1
  • 10
  • 21
  • I haven't probe this solution but I have another question: What is better? This solution or create a custom ActionBar? – Iratzar Carrasson Bores Apr 27 '17 at 13:16
  • 1
    With custom view for actionbar you can do whatever you want - add customize layout, add any views and etc. With style you can only change appearance (color, text style, background) – garmax1 Apr 27 '17 at 15:43
  • Ok. Another question: the code You put in your comment is used with Calligraphy Library or without it? – Iratzar Carrasson Bores Apr 27 '17 at 18:12
  • 1
    You can use it without Calligraphy. But you can simply add in future if will needed just add fontPath in MyCustomTextStyleWithFont. – garmax1 Apr 28 '17 at 05:50
  • Have you checked Calligraphy Library? When I try to add the dependenci and I sync the Gradle File appear this error: _Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'._ – Iratzar Carrasson Bores Apr 29 '17 at 15:20
  • Your error don't apply to Calligraphy. I use Calligraphy and it works fine. – garmax1 Apr 29 '17 at 19:04