状态栏和底部导航栏后面的元素
elements going behind status bar and bottom navigation bar
bottom navigation view is going behind bottom nav bar and the toolbar is going behind the status bar
我是 android 的新手,从第一天起我就一直被这个问题困扰。我试图为工具栏和 bottomnavigationview 设置特定的边距,但我认为这不是一个好的解决方案。有人可以帮我解决这个问题吗?我也试过
android:fitsystemwindows = "真"
但它没有用。下面是片段的 xml 代码
<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"
android:orientation="vertical"
tools:context="fragments.homeUi">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</com.google.android.material.appbar.AppBarLayout>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="167dp"
android:layout_marginBottom="78dp"
android:text="@string/home"
app:layout_constraintBottom_toTopOf="@+id/signOutButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.029"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/signOutButton"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginStart="143dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="168dp"
android:text="@string/signout"
android:textAllCaps="false"
android:textColor="#736B3B"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="409dp"
android:layout_height="230dp"
android:layout_marginStart="1dp"
android:layout_marginTop="140dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="116dp"
app:cardCornerRadius="10dp"
app:layout_constraintBottom_toTopOf="@+id/textView4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPagerHome"
android:layout_width="409dp"
android:layout_height="230dp"
app:layout_constraintCircleRadius="100dp">
</androidx.viewpager2.widget.ViewPager2>
</androidx.cardview.widget.CardView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavbar"
android:layout_width="409dp"
android:layout_height="73dp"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:background="#fff"
app:itemIconTint="@drawable/bottom_nav_icon_color"
app:itemTextColor="#00B8B4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是 activity 的 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="409dp"
android:layout_height="867dp"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_home_acitvity" />
</androidx.constraintlayout.widget.ConstraintLayout>
我认为问题出在这里:
android:layout_width="409dp"
android:layout_height="867dp"
设置如下:
android:layout_width="0dp"
android:layout_height="0dp"
bottom navigation view is going behind bottom nav bar and the toolbar is going behind the status bar
我是 android 的新手,从第一天起我就一直被这个问题困扰。我试图为工具栏和 bottomnavigationview 设置特定的边距,但我认为这不是一个好的解决方案。有人可以帮我解决这个问题吗?我也试过 android:fitsystemwindows = "真" 但它没有用。下面是片段的 xml 代码
<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"
android:orientation="vertical"
tools:context="fragments.homeUi">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</com.google.android.material.appbar.AppBarLayout>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="167dp"
android:layout_marginBottom="78dp"
android:text="@string/home"
app:layout_constraintBottom_toTopOf="@+id/signOutButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.029"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/signOutButton"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginStart="143dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="168dp"
android:text="@string/signout"
android:textAllCaps="false"
android:textColor="#736B3B"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="409dp"
android:layout_height="230dp"
android:layout_marginStart="1dp"
android:layout_marginTop="140dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="116dp"
app:cardCornerRadius="10dp"
app:layout_constraintBottom_toTopOf="@+id/textView4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPagerHome"
android:layout_width="409dp"
android:layout_height="230dp"
app:layout_constraintCircleRadius="100dp">
</androidx.viewpager2.widget.ViewPager2>
</androidx.cardview.widget.CardView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavbar"
android:layout_width="409dp"
android:layout_height="73dp"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:background="#fff"
app:itemIconTint="@drawable/bottom_nav_icon_color"
app:itemTextColor="#00B8B4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav" />
</androidx.constraintlayout.widget.ConstraintLayout>
这是 activity 的 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeActivity">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/fragmentContainerView"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="409dp"
android:layout_height="867dp"
android:layout_marginStart="1dp"
android:layout_marginTop="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_home_acitvity" />
</androidx.constraintlayout.widget.ConstraintLayout>
我认为问题出在这里:
android:layout_width="409dp"
android:layout_height="867dp"
设置如下:
android:layout_width="0dp"
android:layout_height="0dp"