2017-03-04 84 views
1

我面临和我的一个有点复杂片段布局XML的情况下,背景干扰

所以层次如下为:

RelativeLayout的(无背景)
--ScrollView(fillViewPort =真,滚动条=无)
----的FrameLayout(无背景)
------的LinearLayout(无背景)
-------- RelativeLayout的(灰色背景颜色)
---------- EditText
...

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

感谢您的帮助,欢呼声。

+0

指定要使用的Android版本。这将有助于找到答案 – The4thIceman

+0

它发生在几个版本的Android 4.4.2 5.1 6.0 7.0 –

回答

1

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

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

添加在您的清单,这些线路的活动标签下

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