BottomNavigationView 不显示标题和图标
BottomNavigationView not showing titles and icons
我正在尝试在一个 activity 中使用带有 3 个片段的 androidx BottomNavigationView 在这些片段之间导航,但是图标和标题没有显示。
我已经为同一个问题尝试了很多答案并将 labelVisibilityMode 设置为 labled 但没有任何效果
activity布局
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Sorting_activity">
<RelativeLayout
android:id="@+id/triLayout"
android:layout_width="0dp"
android:layout_height="300dp"
app:layout_constraintBottom_toTopOf="@+id/stepsLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
</RelativeLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/stepsLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/buttomLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/triLayout"
>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<RelativeLayout
android:id="@+id/buttomLayout"
android:layout_width="match_parent"
android:layout_height="49dp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="682dp"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cardview_shadow_start_color"
app:menu="@menu/buttom_navigation"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="682dp"
app:labelVisibilityMode="labeled"
app:itemIconTint="@color/colorAccent"
app:itemTextColor="@color/colorPrimary"/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
菜单
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nav_theory"
android:icon="@drawable/ic_baseline_theory_24"
android:title="@string/bottom_navigation_menu_theory" />
<item
android:id="@+id/nav_steps"
android:icon="@drawable/ic_baseline_sort_24"
android:title="@string/bottom_navigation_menu_steps"
/>
<item
android:id="@+id/nav_code"
android:icon="@drawable/ic_baseline_code_24"
android:title="@string/bottom_navigation_menu_code" />
</menu>
尝试清理项目并重建
尝试这种方式它适用于我的
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/stepsLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
app:labelVisibilityMode="labeled"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
如果您看不到图标,请尝试添加:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
app:labelVisibilityMode="labeled"
android:visibility="visible"
app:itemBackground="#ffffff"
app:itemTextColor="#ffffff"
app:itemIconTint="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/menu_navegacion" />
我正在尝试在一个 activity 中使用带有 3 个片段的 androidx BottomNavigationView 在这些片段之间导航,但是图标和标题没有显示。
我已经为同一个问题尝试了很多答案并将 labelVisibilityMode 设置为 labled 但没有任何效果
activity布局
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Sorting_activity">
<RelativeLayout
android:id="@+id/triLayout"
android:layout_width="0dp"
android:layout_height="300dp"
app:layout_constraintBottom_toTopOf="@+id/stepsLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
</RelativeLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/stepsLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@+id/buttomLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/triLayout"
>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<RelativeLayout
android:id="@+id/buttomLayout"
android:layout_width="match_parent"
android:layout_height="49dp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="682dp"
>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cardview_shadow_start_color"
app:menu="@menu/buttom_navigation"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="682dp"
app:labelVisibilityMode="labeled"
app:itemIconTint="@color/colorAccent"
app:itemTextColor="@color/colorPrimary"/>
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
菜单
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nav_theory"
android:icon="@drawable/ic_baseline_theory_24"
android:title="@string/bottom_navigation_menu_theory" />
<item
android:id="@+id/nav_steps"
android:icon="@drawable/ic_baseline_sort_24"
android:title="@string/bottom_navigation_menu_steps"
/>
<item
android:id="@+id/nav_code"
android:icon="@drawable/ic_baseline_code_24"
android:title="@string/bottom_navigation_menu_code" />
</menu>
尝试清理项目并重建 尝试这种方式它适用于我的
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/stepsLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
app:labelVisibilityMode="labeled"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
如果您看不到图标,请尝试添加:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
app:labelVisibilityMode="labeled"
android:visibility="visible"
app:itemBackground="#ffffff"
app:itemTextColor="#ffffff"
app:itemIconTint="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/menu_navegacion" />