java - BottomNavigation 覆盖片段
问题描述
我使用了默认的 Android Studio 底部导航,结果是这样的:
xml文件是这样的:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation"/>
</androidx.constraintlayout.widget.ConstraintLayout>
如何将“底部”设置为导航顶部?
解决方案
好吧...我添加了这一行:
android:layout_marginBottom="?attr/actionBarSize"
在片段部分。像这样:
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@+id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation"
android:layout_marginBottom="?attr/actionBarSize"/>
推荐阅读
- python - TypeError:预期的字符串或类似字节的对象python
- typescript - TS - class method is undefined in callback
- ruby-on-rails - Devise issue with LDAP Auth in Prod Only
- python - 如何删除为菜单打开单独窗口的选项?
- javascript - 了解 Vue 中的 panzoom
- java - In Hibernate/JPA how to tell if the ConstraintViolationException is a PK, a FK, or a unique key violation?
- java - 如何在 Firebase 数据库 Android 的子列表中搜索?
- c - Semantic versioning: minor or major change?
- python - Anchor 的值在 tkinter,python3.7 中看起来颠倒了
- html - 滚动卡在 iOS 上