Android - 如何更改底部导航栏文本的字体系列 [英] Android - How to change bottom navigation bar text's font family

查看:33
本文介绍了Android - 如何更改底部导航栏文本的字体系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 android 页面中创建了一个底部栏导航.但现在我想在底部导航文本中应用自定义字体系列.

I have created a bottom bar navigation in my android page. But now I want to apply the custom font-family in bottom navigation texts.

这是.xml文件中的底部导航代码:

This is the bottom navigation code in .xml file:

<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/文件夹中添加字体文件,将字体捆绑为资源

add the font file in the res/font/ folder to bundle fonts as resources

然后

您可以使用样式资源更改它.在你的styles.xml 中:

You can change it using style resources. In your styles.xml:

<style name="Widget.BottomNavigationView" 
    parent="Widget.Design.BottomNavigationView">
    <item name="fontFamily">@font/your_font</item>
</style>

然后将其应用为您视图中的主题:

Then apply it as a theme in your view:

<android.support.design.widget.BottomNavigationView
    ...
    android:theme="@style/Widget.BottomNavigationView"
/>

刚刚检查了我的应用程序,它运行良好.

Just checked on my app, it works fine.

参考:https://developer.android.com/guide/topics/ui/look-and-feel/fonts-in-xml.html#fonts-in-code

这篇关于Android - 如何更改底部导航栏文本的字体系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆