当前位置: 首页 > 知识库问答 >
问题:

KOTLIN-BottomNavigationBar中的第一个项目不可见,标题问题

慕鹏
2023-03-14

我有一个包含5个项目的BottomNavigationBar。除了名称和图标,第一个项目与其他项目相同。这是bottom_nav菜单的xml

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

    <item
        android:id="@+id/name_configuration"
        android:title="Name Mech"
        android:icon="@drawable/ic_action_name"
        />

    <item
        android:id="@+id/mech_skills"
        android:title="Skills"
        android:icon="@drawable/ic_action_skills"
        />

    <item
        android:id="@+id/stat_hub"
        android:title="Stat Hub"
        android:icon="@drawable/ic_action_stats"
        />

    <item
        android:id="@+id/mech_weapons"
        android:title="Weapons"
        android:icon="@drawable/ic_action_weapon"
        />

    <item
        android:id="@+id/mech_systems"
        android:title="Systems"
        android:icon="@drawable/ic_action_system"
        />
</menu>

这是用于图标的绘图的xml

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24"
    android:tint="#FFFFFF"
    android:alpha="0.8">
    <path
        android:fillColor="#FF000000"
        android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>

最后,这是我用于Bar本身的xml

<com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btm_nav"
        app:layout_constraintBottom_toBottomOf="parent"
        android:background= "@color/colorPrimary"
        app:menu="@menu/bottom_nav"/>

其余可绘图项的xml完全相同(它们使用不同的图标,但这与xml本身无关)。但是,名称_配置项在底部导航栏中不可见。单击时,它的行为与其他项目相同(它们传递SharedReferences值并移动到不同的活动),只是不可见。但是,当按下底部导航栏上的其他按钮时,在应用程序进入下一个活动之前,“名称”按钮短暂变为正确的颜色/透明度,并且“名称”按钮再次变为不可见。

此外,Name Mech的标题是底部导航栏中任何按钮的唯一标题。“名称机械”出现在底部导航栏的图标下方,但“技能”、“状态”、“武器”和“系统”不会出现在底部导航栏的相应图标下方。

任何指导都将不胜感激。

共有3个答案

汪同
2023-03-14

我有同样的问题,但现在我的代码工作正常。试试我的代码:

在build.gradle(: app):

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:design:28.0.0'
}

在XML中:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigationView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:layout_marginStart="0dp"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:itemBackground="@color/colorPrimary"
        app:itemIconTint="#fff"
        app:itemTextColor="#fff"
        app:menu="@menu/menu"
        app:labelVisibilityMode="unlabeled"/>
</androidx.constraintlayout.widget.ConstraintLayout>
卜盛
2023-03-14

当您没有为BottomNavigationView设置“labelVisibilityMode”时,其结果是自动模式,在该模式下,只有第一个项目被标记,另一个项目被取消标记。当您将“labelVisibilityMode”设置为“已标记”时,所有项目都将被标记。

在defult模式下,它是:

app:labelVisibilityMode="auto"

您可以将其更改为:

app:labelVisibilityMode="labeled"

此外,如果你根本不想要标签,只需设置:

app:labelVisibilityMode="unlabeled"
邹英发
2023-03-14

视图正在隐藏标签。您可以在底部导航视图上设置app:labelVisibilityMode=“labeled”,以强制它们出现。我相信如果他们占用太多的空间,文本就会被切断。

 类似资料:
  • 祝大家今天过得愉快!我对c#的建筑废料项目还不熟悉。现在我正试图从一个网站上抓取标签href属性的内容。但还不能得出好的结论!以下是网页的结构: 我将删除href url链接字符串的内容(此处:“/national/南非/psl/20192020/regular seasure/r53038/”)。这是我的c#scraping项目: 我尝试了其他一些方法来删除href属性的内容。但仍然没有得到正确

  • 问题内容: 在我的JTable中不可见的列标题我已经创建了一个JPanel并将JTable添加到JPanel中。 问题答案: JTable的API指出: “请注意,如果希望在独立视图(JScrollPane外部)中使用JTable并希望显示标题,则可以使用getTableHeader()获取它并单独显示它。” 或者只是将表添加到滚动窗格,然后将滚动窗格添加到面板…

  • 问: 我有一个普通的web项目,想在这个项目中调用WorkerMan的接口,给客户端推送数据。 答: 基于Workerman可以参考以下连接 1、Channel组件推送例子(支持多进程/服务器集群,需要下载Channel组件) 2、基于Worker推送(单进程,最简单) 基于GatewayWorker参考下面连接 在其它项目中通过GatewayWorker推送(支持多进程/服务器集群,支持分组、组

  • 等级 6.1.1 我一直在尝试使用Kotlin DSL转换我项目的gradle文件,但迄今为止失败了。我所有的项目都是Java的多项目构建。我在这里遵循了插件子项目示例 看起来是这样的: 子项目似乎不理解java插件,所有“实现”行都有一个未解析的引用。

  • 当我将一个对象放到场景中时,通过变形目标重新调整他的大小,如本例所示: https://threejsdoc.appspot.com/doc/three.js/examples/webgl_morphtargets.html 当我将相机移出对象的原始大小,但仍在查看重新调整大小的部分时,对象消失了。 这意味着,当我拉伸盒子100次时,我仍然需要看他原来的中心,当我只看他重新调整大小的部分时,它就不

  • 如何使组合框中的一个项目无法选择,因为我需要将组合框中的项目与子主题分开。 有可能单独修改特定项目的字体吗?