【问题标题】:I need to hide title of items in bottom navigation bar我需要在底部导航栏中隐藏项目的标题
【发布时间】:2018-02-07 09:26:26
【问题描述】:

我创建了底部导航栏,我只需要隐藏标题和显示图标,但是当我用空字符串写标题时,图标和底部之间有很大的空间,它只是用空字符串替换字符串,我进行了很多搜索,但我没有t找到解决方案,所以任何帮助

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.easyschools.student.HomeActivity">

<FrameLayout
    android:id="@+id/main_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/navigation"
    android:layout_alignParentTop="true">
 </FrameLayout>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="@android:color/white"
    android:layout_alignParentBottom="true"
    app:menu="@menu/navigation"/>

</RelativeLayout>

导航.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/nav_messages"
        android:icon="@drawable/msg_icon"
        android:title=""/>

    <item
        android:id="@+id/nav_home"
        android:icon="@drawable/home_icon"
        android:title=""
        android:checked="true"/>

    <item
        android:id="@+id/nav_notify"
        android:icon="@drawable/notify_icon"
        android:title=""/>

    <item
        android:id="@+id/nav_my_profile"
        android:icon="@drawable/user_icon"
        android:title=""/>
</menu>

【问题讨论】:

标签: android android-support-design


【解决方案1】:

从支持库28.0.0-alpha1开始,你可以使用:

app:labelVisibilityMode="unlabeled"

隐藏标题和

app:itemHorizontalTranslationEnabled="false"

添加:

xmlns:app="http://schemas.android.com/apk/res-auto"

在 xml 中禁用转移模式到您的 BottomNavigationView

【讨论】:

    【解决方案2】:

    BottomNavigationView 有很多限制。

    例如,您可以使用空的String "" 设置标题,但我建议您使用库来轻松增强底部导航栏。

    你可以试试这个:https://github.com/ittianyu/BottomNavigationViewEx

    【讨论】:

    • 如果我选择另一个选项卡,如何更改图标?我的不能改变
    【解决方案3】:

    您可以使用 BottomNavigationView 的以下属性:

    app:labelVisibilityMode="unlabeled"
    

    在您的布局中还包括以下行:

     xmlns:app="http://schemas.android.com/apk/res-auto"
    

    作为参考,您可以使用以下链接: https://www.11zon.com/zon/android/remove-bottom-navigation-view-title-in-android.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 1970-01-01
      相关资源
      最近更新 更多