操作栏顶部奇怪的白线
Weird white line on top of Action Bar
我同时实现了一个DrawerNavigationView
和一个BottomNavigationView
,但问题是ActionBar
...默认片段没问题 enter image description here But changing fragment
it creates a weird white line on the top of the ActionBar
, which is not anymore in the right position... Do u maybe know why?enter image description here 谢谢你的帮助 D:
XML 主要代码 activity 片段容器
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:theme="@style/Theme2"
app:itemIconTint="@color/white_darker"
app:itemRippleColor="@color/white_darker"
app:itemTextColor="@color/white_darker"
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_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="?android:attr/actionBarSize"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_header"
app:itemTextAppearance="?textAppearanceListItem"
app:menu="@menu/navigation_drawer" />
XML 有问题的片段代码(Empty ConstraintLayout)
<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:background="@color/dark"
tools:context=".HomeUi.Notifications.NotificationsFragment">
在您的 styles.xml
文件中,在 parent
之后尝试 NoActionBar
。其他问题可能是 fragment
.
中有 linearlayout
的剩余部分
对于将来遇到同样问题的人,我找到了解决方案,添加一个 CoordinatorLayout 作为根,包装主片段容器上的所有 xml 代码,并在其上使用 android:fitsSystemWindows="true" ,现在一切正常!
我同时实现了一个DrawerNavigationView
和一个BottomNavigationView
,但问题是ActionBar
...默认片段没问题 enter image description here But changing fragment
it creates a weird white line on the top of the ActionBar
, which is not anymore in the right position... Do u maybe know why?enter image description here 谢谢你的帮助 D:
XML 主要代码 activity 片段容器
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
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"
android:theme="@style/Theme2"
app:itemIconTint="@color/white_darker"
app:itemRippleColor="@color/white_darker"
app:itemTextColor="@color/white_darker"
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_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:navGraph="@navigation/mobile_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginTop="?android:attr/actionBarSize"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_header"
app:itemTextAppearance="?textAppearanceListItem"
app:menu="@menu/navigation_drawer" />
XML 有问题的片段代码(Empty ConstraintLayout)
<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:background="@color/dark"
tools:context=".HomeUi.Notifications.NotificationsFragment">
在您的 styles.xml
文件中,在 parent
之后尝试 NoActionBar
。其他问题可能是 fragment
.
linearlayout
的剩余部分
对于将来遇到同样问题的人,我找到了解决方案,添加一个 CoordinatorLayout 作为根,包装主片段容器上的所有 xml 代码,并在其上使用 android:fitsSystemWindows="true" ,现在一切正常!