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

标签 android background keyboard

我正面临着我的一些复杂 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/

相关文章:

php - Client-Server-Communication with php and android

android - 类型错误 :Request path contains unescaped characters - npm & cordova

objective-c - 在iOS7中,为什么选中的单元格的背景色总是灰色?

android - 9 补丁缩小问题

android - 在 Android 中发布巨大的 JSON 对象

android - 如何使用 Flows 处理数据库调用错误

html - 在鼠标悬停和鼠标单击时更改菜单颜色

iphone - 如何制作顶部带有文本字段的键盘?

wpf - 响应WPF中的 "Back"和 "Forward"按钮

c# - 在 Windows 10 Store App 中显示触摸键盘