Android 如何隐藏键盘上显示的页脚组件';editText在片段中聚焦时位于顶部?

Android 如何隐藏键盘上显示的页脚组件';editText在片段中聚焦时位于顶部?,android,android-fragments,uiscrollview,Android,Android Fragments,Uiscrollview,片段布局 实际上,页脚设置在活动类中,而edittext则放置在片段中。 清单文件 <activity android:name="HomeController" android:label="@string/app_name" android:windowSoftInputMode="stateHidden|adjustPan"/> 这些是我使用的代码片段,但它不起作用

片段布局


实际上,页脚设置在活动类中,而edittext则放置在片段中。 清单文件

 <activity
        android:name="HomeController"
        android:label="@string/app_name"
        android:windowSoftInputMode="stateHidden|adjustPan"/>
这些是我使用的代码片段,但它不起作用! 注意:在Fragment UI中,整个屏幕有一个滚动视图, 不知道为什么会这样?实际上我不想让我的页脚在键盘顶部。

有没有关于如何解决这种行为的建议?对于回复来说,它是合适的:)

在xml文件的父布局中使用android:windowSoftInputMode=“hidden”。另外,如果它具有layoutAbove属性,则尝试将其删除。

尝试在清单文件中添加以下内容: android:WindowsofInputMode=“StateAllwayshidden | adjustResize”

同时从片段中删除以下内容:
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_输入_状态_始终隐藏| WindowManager.LayoutParams.SOFT_输入_调整_平移)

将此添加到您的活动中

我没有测试,但这可能有效。但这是一种糟糕的方式(


上传您的片段布局也在我有父布局(相对布局)之前,在此布局中我使用了滚动视图,并在此视图中添加了整个设计。抱歉,它不起作用,我在父布局中添加了android:WindowsOfInputMode=“stateHidden”,并更改了属性上方的整个布局:(感谢您的回复@Kamran Sajid,但它不起作用:(感谢您的回复:)我有一个疑问,这contentView是parentLayout吗?@varshajeevan ups!是的,是的。我从我的旧UTIL文件复制了它,这就是为什么不一致的原因(.I更新了答案。也许您可以使用parentLayout。非常感谢:)它工作正常。我所做的是在键盘显示时禁用底部栏,在键盘隐藏时启用。不客气!但正如我所说的,这不是一个好方法…因为它可能在某些手机上表现不好(我个人到目前为止没有任何问题),可能在拆分屏幕模式下。哦,让我检查一下:)
 getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
 contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
    @Override
    public void onGlobalLayout() {
    
        Rect r = new Rect();
        View rootView = getWindow().getDecorView().getRootView();
        rootView.getWindowVisibleDisplayFrame(r);
        int screenHeight = rootView.getHeight();
    
        // r.bottom is the position above soft keypad or device button.
        // if keypad is shown, the r.bottom is smaller than that before.
        int keypadHeight = screenHeight - r.bottom;
    
        Log.d(TAG, "keypadHeight = " + keypadHeight);
    
        if (keypadHeight > screenHeight * 0.15) { // 0.15 ratio is perhaps enough to determine keypad height.
            // keyboard is opened
            //set bottom navigation(footer) bar to View.GONE
        }
        else {
            // keyboard is closed
           //set bottom navigation bar(footer) to View.VISIBLE
        }
    }
    });