我一直在尝试将BottomNavigationView添加到屏幕。通常,它可以按预期工作,但是当键盘在屏幕上可见时,BottomNavigationView的高度会意外增加。
我想要固定高度,使其与键盘保持一致。 BottomNavigationView与键盘之间应该没有任何间隙。
我添加了代码和屏幕截图,以帮助您了解我的问题。
<?xml version="1.0" encoding="utf-8"?>
<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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Other views -->
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="@menu/bottom_navigation_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<!-- Other views -->
</androidx.drawerlayout.widget.DrawerLayout>
删除CoordinatorLayout中的fitsSystemWindows:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
并在清单文件中更改您的活动的windowSoftInputMode:
<activity
android:name=".YourActivity"
android:windowSoftInputMode="adjustResize">