1

I have troubles with making it work. It only works with default fonts like sans-seriff. Any imported fonts work with all textviews, however not with the collapsing toolbar. Please help.

Styles.xml

<style name="AppBarTitleStyle" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:fontFamily">@font/amatica_sc_reg</item>
    <item name="android:titleTextColor">@android:color/white</item>
</style>

CollapsingToolbar.xml

   <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="308dp"
        android:background="@color/color_secondary"
        app:expanded="false">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsingtoolbarid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/colliding"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="exitUntilCollapsed|scroll|snap"
            app:title="Learn Miwok"
            app:expandedTitleTextAppearance="@style/AppBarTitleStyle"
            app:collapsedTitleTextAppearance="@style/AppBarTitleStyle">
 <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbarid"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin">

            </androidx.appcompat.widget.Toolbar>

        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>
Filip Szczybura
  • 407
  • 5
  • 14

1 Answers1

1

you can add font with java by using this below code

final Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/amatica_sc_reg");
collapsingToolbar.setCollapsedTitleTypeface(tf);
collapsingToolbar.setExpandedTitleTypeface(tf);