【发布时间】:2020-03-04 23:30:47
【问题描述】:
我有一个包含 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>
这是我用于图标的drawable的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 本身无关)。但是,name_configuration 项在底部导航栏中是不可见的。单击时,它的行为与其他项目相同(它们传递 SharedPreferences 值并移动到不同的活动),只是不可见。但是,当按下底部导航栏上的其他按钮时,名称按钮会在应用程序进入下一个活动之前短暂变为正确的颜色/透明度,并且名称按钮再次变得不可见。
此外,Name Mech 的标题是底部导航栏中任何按钮的唯一标题。 “Name Mech”出现在底部导航栏的图标下方,但“Skills”、“StatHub”、“Weapons”和“Systems”并没有出现在底部导航栏各自的图标下方。
任何指导将不胜感激。
【问题讨论】:
标签: android xml kotlin bottomnavigationview android-bottomnav