gpt4 book ai didi

android - 键盘关闭时的背景故障

转载 作者:行者123 更新时间:2023-11-29 01:11:38 25 4
gpt4 key购买 nike

我正面临着我的一些复杂 fragment 布局 xml 的情况,

因此层次结构如下:

RelativeLayout(无背景)
--ScrollView (fillViewPort=true, scrollbars=none)
----FrameLayout(无背景)
------LinearLayout(无背景)
--------RelativeLayout(灰色背景色)
----------编辑文本
...

因此,当编辑文本被点击时,它会打开软键盘(正如预期的那样),并且当按下后退键或某些点击 block 时,它会使用以下方法隐藏键盘:

try {
InputMethodManager inputMethodManager = (InputMethodManager) GlobalApplication.getInstance().getCurrentActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(GlobalApplication.getInstance().getCurrentActivity().getCurrentFocus().getWindowToken(), 0);
} catch (Exception e) {
if (e.getMessage() != null)
Log.d("KeyboardError", e.getMessage());
}

问题是我的 Activity 背景是红色的,当隐藏键盘操作发生时,我看到的是 Activity 的背景而不是 RelativeLayout 的灰色背景,这就像一个小故障或卡住。一段时间后它恢复正常并显示正确的背景。

谢谢你的帮助,干杯。

最佳答案

在 super.onCreate(savedInstanceState) 之后的基础 Activity onCreate() 中使用它;

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

将这些行添加到您的 Activity 标签下的 list 中

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:windowSoftInputMode="stateHidden|adjustPan"

关于android - 键盘关闭时的背景故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42597256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com