【问题标题】:BottomNavigationView's height get increased when soft keyboard is visible in the screen. How to fix it's height?当软键盘在屏幕上可见时,BottomNavigationView 的高度会增加。如何固定它的高度?
【发布时间】:2020-09-02 07:09:54
【问题描述】:

我一直在尝试将 BottomNavigationView 添加到屏幕。通常它会按预期工作,但是当键盘在屏幕中可见时,BottomNavigationView 的高度会意外增加。

我想要的是固定高度,使其与键盘保持一致。 BottomNavigationView 和 Keyboard 之间不应有任何间隙。

我添加了代码和屏幕截图来帮助您理解我的问题。

<?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>

【问题讨论】:

    标签: android material-design android-softkeyboard bottomnavigationview softkeys


    【解决方案1】:

    删除 CoordinatorLayout 中的 fitSystemWindows:

    <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">
    

    【讨论】:

    • 感谢您的回答。现在已修复。但我不知道幕后发生了什么以及为什么我会出现这种行为。你能给我解释一下吗?或者指向我可以从中获取知识的任何博客/文档?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    相关资源
    最近更新 更多