BottomNavigationView即使在视图的顶部也是可见的

问题描述 投票:0回答:1

我的屏幕有3个主要部分

  • 工具栏
  • homeContaner(将容纳BottomNavigationView的片段)
  • mainContainer(主机初始屏幕或占据整个屏幕的任何屏幕)

当用飞溅BottomNavigationView替换mainContainer时,也显示我尝试将背景色添加到mainContainer,发现BottomNavigationViewmainContainerTop

也试图向mainContainer添加标高,但没有新结果

截屏enter image description here

完整代码

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".feature.home_Activity.HomeActivity">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:titleTextColor="@android:color/white"/>

    <FrameLayout
        android:id="@+id/homeContainer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="@id/dummy"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/toolbar" />

    <View
        android:id="@+id/dummy"
        android:layout_width="match_parent"
        android:layout_height="@dimen/_10sdp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@id/navigation" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="1dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:menu="@menu/navigation" />

    <FrameLayout
        android:id="@+id/mainContainer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:elevation="10dp"
        android:background="#ffaaff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
android bottomnavigationview
1个回答
0
投票
LinearLayout包装

BottomNavigationView解决了问题

<?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" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".feature.home_Activity.HomeActivity"> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" app:layout_constraintTop_toTopOf="parent" app:titleTextColor="@android:color/white" /> <FrameLayout android:id="@+id/homeContainer" android:layout_width="0dp" android:layout_height="0dp" app:layout_constraintBottom_toBottomOf="@id/dummy" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/toolbar" /> <View android:id="@+id/dummy" android:layout_width="match_parent" android:layout_height="@dimen/_10sdp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="@id/navigationContainer" /> <androidx.appcompat.widget.LinearLayoutCompat android:id="@+id/navigationContainer" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintBottom_toBottomOf="parent"> <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bn_bg" app:elevation="1dp" app:itemBackground="@drawable/bn_item__bg" app:itemIconTint="@color/secondaryTextColor" app:itemTextColor="@color/primaryTextColor" app:layout_constraintBottom_toBottomOf="parent" app:menu="@menu/navigation" /> </androidx.appcompat.widget.LinearLayoutCompat> <FrameLayout android:id="@+id/mainContainer" android:layout_width="0dp" android:layout_height="0dp" app:elevation="10dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>
© www.soinside.com 2019 - 2024. All rights reserved.