键盘闭合上的背景故障

堪伯克

我面临着我的一个有点复杂的片段布局 xml 的情况,

所以层次结构如下:

RelativeLayout (无背景)
--ScrollView (fillViewPort=true, scrollbars=none)
----FrameLayout (无背景)
------LinearLayout (无背景)
--------RelativeLayout (背景色为灰色)
----------EditText
...

因此,当单击编辑文本时,它会打开软键盘(如预期的那样),当回按或使用以下方法隐藏键盘的某些单击块时:

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());
    }

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

谢谢帮助,加油。

阿里坎特梅尔

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

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

或者

在活动标签下的清单中添加这些行

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章