键盘关闭时出现背景故障 [英] Background glitch on keyboard closure

查看:136
本文介绍了键盘关闭时出现背景故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面对的是我的片段布局XML有点复杂的情况,

I'm facing a situation with a little complex fragment layout xml of mine,

因此,层次结构如下:

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

RelativeLayout (no background)
--ScrollView (fillViewPort=true, scrollbars=none)
----FrameLayout (no background)
------LinearLayout (no background)
--------RelativeLayout (background color of gray)
----------EditText
...

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

So when the edittext clicked it opens soft keyboard (as expected), and when back press or some click block which hides keyboard with following method:

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的灰色背景,并且它像毛刺或卡住.一段时间后,它恢复正常并显示适当的背景.

The problem is I've a red background for the activity and when the hiding keyboard action happens, I'm seeing the activity's background instead of the gray background of the RelativeLayout, and it's happening like a glitch or stuck. After awhile it comes back to normal and shows proper background.

谢谢您的帮助.

推荐答案

在super.onCreate(savedInstanceState);

Use this in your base activity onCreate() after super.onCreate(savedInstanceState);

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

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

Add these lines in your manifest under your activity tag

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

这篇关于键盘关闭时出现背景故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆