【发布时间】:2020-09-07 07:26:23
【问题描述】:
在我的项目中,我将navhost 片段和BottomNavigationView 添加到我的activity_main 中,导航时一切似乎都很好,但是当我单击工具栏选项时,我导航到另一个页面,但我仍然看到底部导航视图,如何我看不到底部导航视图吗?我添加了导航 xml 来导航所有页面,并在我的资源文件上创建了底部导航菜单。唯一的问题是当我导航到底部导航页面内的另一个页面时,我仍然看到底部导航视图。
<androidx.appcompat.widget.Toolbar
android:id="@+id/app_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/app_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/text_some"
android:fontFamily="@font/lobster_two"
android:text="@string/text_some"
android:textColor="@color/colorSecondary"
android:textSize="24sp" />
</androidx.appcompat.widget.Toolbar>
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/app_toolbar"
app:layout_constraintVertical_bias="0.0"
app:navGraph="@navigation/bottom_navigation_graph" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottom_navigation_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
android:showAsAction="always|withText"
app:itemIconSize="22dp"
app:itemIconTint="@drawable/bottom_nav_color"
app:itemTextColor="@drawable/bottom_nav_color"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_menu" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/circle_view_image"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_marginBottom="25dp"
android:elevation="99dp"
android:src="@drawable/image"
app:layout_constraintBottom_toBottomOf="@+id/bottom_nav"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
标签: android kotlin navigation android-jetpack-navigation