Android 如何避免出现软键盘时只向上推底部导航栏

Android 如何避免出现软键盘时只向上推底部导航栏,android,android-softkeyboard,android-bottomnav,Android,Android Softkeyboard,Android Bottomnav,在我的android应用程序中,我有这样一个视图 有一个main活动,它有一个bottomNavBar,活动中有一个片段,在底部有两个按钮 我要做的是,当软键盘出现时,导航栏应位于底部(键盘后面),但这两个按钮应向上推,并在键盘顶部可见 如果我在manifest文件中为main活动设置了android:windowSoftInputMode=“adjustResize”,然后键盘向上推底部导航栏和按钮 如果我将android:windowSoftInputMode=“adjustResize”

在我的android应用程序中,我有这样一个视图

有一个
main活动
,它有一个
bottomNavBar
,活动中有一个片段,在底部有两个按钮

我要做的是,当软键盘出现时,导航栏应位于底部(键盘后面),但这两个按钮应向上推,并在键盘顶部可见

如果我在
manifest
文件中为main活动设置了
android:windowSoftInputMode=“adjustResize”
,然后键盘向上推底部导航栏和按钮

如果我将android:windowSoftInputMode=“adjustResize”仅设置为片段(以编程方式),那么它仍然显示相同的行为

我该怎么做?如有任何建议,将不胜感激

这是我的活动xml

    <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <LinearLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:orientation="vertical"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <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:navGraph="@navigation/mobile_navigation"
            android:layout_weight="@integer/int_two"/>

        <com.google.android.material.bottomnavigation.BottomNavigationView
            app:itemIconTint="@drawable/bottom_navigation_selector"
            app:itemTextColor="@drawable/bottom_navigation_selector"
            android:id="@+id/nav_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="@integer/int_zero"
            android:background="?android:attr/windowBackground"
            app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
            app:menu="@menu/bottom_nav_menu" />

    </LinearLayout>
</layout>

我也面临同样的问题,经过多次努力,我找到了一个适合我的解决方案。我所做的是,当键盘出现时使底部导航栏可见性消失,反之亦然

尝试此操作以获得键盘打开和关闭事件-

view.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
      Rect r = new Rect();
      view.getWindowVisibleDisplayFrame(r);
      if (view.getRootView().getHeight() - (r.bottom - r.top) > 500) {
        // on Keyboard Open
        llBottomNavBarLayout.setVisibility(View.GONE);
      } else {
        // on keyboard close
        llBottomNavBarLayout.setVisibility(View.VISIBLE);
      }
    });
为了获得我使用的视图

LayoutInflater layoutInflater = getLayoutInflater();
View view = layoutInflater.inflate(R.layout.activity_abc, null);

我也面临同样的问题,经过多次努力,我找到了一个适合我的解决方案。我所做的是,当键盘出现时使底部导航栏可见性消失,反之亦然

尝试此操作以获得键盘打开和关闭事件-

view.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
      Rect r = new Rect();
      view.getWindowVisibleDisplayFrame(r);
      if (view.getRootView().getHeight() - (r.bottom - r.top) > 500) {
        // on Keyboard Open
        llBottomNavBarLayout.setVisibility(View.GONE);
      } else {
        // on keyboard close
        llBottomNavBarLayout.setVisibility(View.VISIBLE);
      }
    });
为了获得我使用的视图

LayoutInflater layoutInflater = getLayoutInflater();
View view = layoutInflater.inflate(R.layout.activity_abc, null);

谢谢你的更新。我试过你的布局。添加到相应活动的清单
android:windowSoftInputMode=“adjustNothing”
请注意,这也会影响晶圆厂和其他锚定视图


谢谢您的更新。我试过你的布局。添加到相应活动的清单
android:windowSoftInputMode=“adjustNothing”
请注意,这也会影响晶圆厂和其他锚定视图



您是否尝试过android:WindowsOfInputMode=“adjustPan | stateHidden”?您是否尝试过android:WindowsOfInputMode=“adjustPan | stateHidden”?我尝试过,但没有成功。我已经为你们更新了这个问题。你可以看到我尝试过的活动代码,但它不起作用。我已经为你们更新了这个问题。你可以看到活动代码它工作了谢谢,但是你能告诉我为什么我们使用价值500吗?它工作了谢谢,但是你能告诉我为什么我们使用价值500吗?