AndroidManifest. xml
android:theme="@style/AppTheme"
стилей. xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:fontFamily">@font/montserrat</item>
<item name="fontFamily">@font/montserrat</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
Activity_dashboard. xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include layout="@layout/content_dashboard" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@drawable/background_top_right_radius_white"
android:fitsSystemWindows="false"
app:headerLayout="@layout/nav_header">
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_160sdp"
android:divider="@color/white"
android:dividerHeight="0dp"
android:groupIndicator="@null" />
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
content_dashboard. xml (Только общий доступ к текстовому коду)
<TextView
android:id="@+id/tvDashboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_45sdp"
android:layout_marginTop="@dimen/_10sdp"
android:text="@string/dashboard"
android:textColor="@color/black"
android:textSize="@dimen/_20sdp"
android:textStyle="bold" /> //this is not working
Панель инструментов. java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
TextView tvDashboard = findViewById(R.id.tvDashboard);
tvDashboard.setTypeface(null, Typeface.BOLD); //this is not working
}
Весь шрифт приложения установлен на Монтсеррат с использованием https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts#via - android -студия . Однако в некоторых частях у меня есть заголовки и тому подобное, поэтому я бы хотел изменить стиль на жирный. Он работает в некоторых местах, когда я использую код setTypeface, но не работает в других местах (включая приведенный выше пример). Это странно, и я не уверен, почему он так себя ведет.