2017-03-04 129 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"