【发布时间】:2019-12-18 10:49:06
【问题描述】:
我正在尝试更改可折叠工具栏字体。我的代码在下面
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbarlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/id_collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|snap|enterAlways"
app:title="App Title">
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:src="@drawable/img" />
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/TextViewCustomFont"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<style name="TextViewCustomFont">
<item name="android:fontFamily">fonts/Montserrat-SemiBold.ttf</item>
</style>
我也在使用书法3, 所以,我尝试了 fontPath 而不是 android:fontFamily 然后,我从工具栏移动并检查了 android:theme="@style/TextViewCustomFont" 到 CollapsingToolbarLayout 以及所有这些组合。
我无法更改字体样式。
记住这是 androidx 不是旧的。 stackoverflow 中有很多旧问题,但没有一个像旧问题一样工作。
【问题讨论】:
-
不确定,但我认为字体文件名“Montserrat-SemiBold”中的连字符“-”会导致问题。您是否尝试过删除或替换为下划线“_”?
-
@SafalFrom2050 是的,我试过了,结果一样。