android - 如何更改抽屉导航字体?

标签 android fonts navigation-drawer right-to-left

我想在 android 中使用我自己的抽屉导航字体。我根据这个答案使用 android studio 附带的库:https://stackoverflow.com/a/23632492/4393226 . 但我不知道如何更改字体并使其成为 RTL。 我搜索了很多,找到了如何制作抽屉 RTL。我使用这段代码:

getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

Android - Is Navigation Drawer from right hand side possible?

但如您所知,这仅适用于 API 17 及更高版本。 请帮忙!如何更改菜单字体?如何以正确的方式制作布局 RTL?!

已编辑: 我的字体“TTF”文件在 Assets /字体中,我知道如何使用 java 为 TextView 设置它,但我不知道如何将它设置为抽屉导航菜单。

最佳答案

您可以通过更简单的方式做到这一点。

首先进入 style.xml 并在那里创建一个新样式。

 <style name="RobotoTextViewStyle" parent="android:Widget.TextView">
      <item name="android:fontFamily">@font/sans-serif-smallcaps</item>
 </style>

第二个是转到您的导航 xml 代码并将项目文本外观放在那里。

app:itemTextAppearance="@style/RobotoTextViewStyle"

现在您的最终导航代码应该是这样的。

<android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:itemTextAppearance="@style/RobotoTextViewStyle"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_home"
        app:menu="@menu/activity_home_drawer" />

关于android - 如何更改抽屉导航字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34611619/

相关文章:

android - [UIScreen mainScreen].bounds.size.width 的 Android 等效项是什么?

html - 在网页上使用 Windows 95 字体

java - 在 Java Swing 中扩展 JLabel 以使用给定字体(扩展类中的 super 用法)

android - 调用 ActionBarDrawerToggle.setDrawerIndicatorEnabled(false) 后向上箭头不显示

flutter - 将 ListView 的最后一个元素固定到屏幕底部

安卓.Views.InflateException : Binary XML file line #1: Error inflating class toolbar

android - 可选择在 Android 上使用新的 API

java - 在 Swing 中选择等宽字体的正确方法

android - 使用动态 fragment 加载抽屉导航 slider

Android Studio 无法通过 SVN 进行身份验证