我在我的 android 页面中创建了一个底部栏导航。但现在我想在底部导航文本中应用自定义字体系列。
这是 .xml
文件中的底部导航代码:
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/bottomNavView_Bar"
android:background="@drawable/white_grey_border_top"
app:menu="@menu/bottom_navigation_menu">
</android.support.design.widget.BottomNavigationView>
另外,bottom_navigation_menu.xml
中的代码:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="@+id/ic_newsfeed"
android:icon="@drawable/ic_menu_camera"
android:title="NEWSFEED"
/>
<item
android:id="@+id/ic_explorer"
android:icon="@drawable/ic_home_black_24dp"
android:title="EXPLORER"
/>
<item
android:id="@+id/ic_notify"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="NOTIFY"
/>
<item
android:id="@+id/ic_more"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="MORE"
/>
</menu>
我们将不胜感激。
提前致谢!
最佳答案
在 res/font/文件夹中添加字体文件以将字体 bundle 为资源
然后
您可以使用样式资源对其进行更改。 在你的styles.xml中:
<style name="Widget.BottomNavigationView"
parent="Widget.Design.BottomNavigationView">
<item name="fontFamily">@font/your_font</item>
</style>
然后将其作为主题应用到您的 View 中:
<android.support.design.widget.BottomNavigationView
...
android:theme="@style/Widget.BottomNavigationView"
/>
刚刚检查了我的应用程序,它运行良好。
引用: https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html#fonts-in-code
关于Android - 如何更改底部导航栏文本的字体系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45604944/