Background glitch on keyboard closure

核能气质少年 提交于 2019-12-23 23:06:53

问题


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

So the hierarchy follows as:

RelativeLayout (no background)
--ScrollView (fillViewPort=true, scrollbars=none)
----FrameLayout (no background)
------LinearLayout (no background)
--------RelativeLayout (background color of gray)
----------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());
    }

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.

Thanks for help, cheers.


回答1:


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

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

or

Add these lines in your manifest under your activity tag

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


来源:https://stackoverflow.com/questions/42597256/background-glitch-on-keyboard-closure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!