2013-07-27 104 views
0

我使用edittext創建了WindowPopup。當我專注於它時,軟鍵盤顯示並取代上方的彈出窗口,所以我看不到我在輸入什麼。我想在鍵盤上方顯示沒有任何視圖位移的鍵盤。 我讀過,我可以改變它的softInputMode,所以我創建類從EditText擴展,並嘗試更改onFocusListener中的inputMode,但它沒有幫助。如何在顯示軟鍵盤後防止窗口彈出位移?

setOnFocusChangeListener(new OnFocusChangeListener() { 

    @Override 
    public void onFocusChange(View veiw, boolean has_focus) { 

     if (has_focus) { 
      //Try to change input mode to prevent displacing 
      ((Activity) getContext()).getWindow().setSoftInputMode(
      WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); 
     } else { 
      //.. return back previous input mode 
     } 

}); 

我這樣做,因爲我只有在這個彈出需要這樣的行爲,但我甚至試圖改變action屬性在我manifets文件

android:windowSoftInputMode="adjustNothing" 

android:windowSoftInputMode="stateHidden" 

我可以顯示沒有任何視角的鍵盤?

P.S.我使用的是Android API 15

回答

0

當PopupWindow創建彈出視圖時,它將使用softInputMode設置新的WindowManager.LayoutParams,它將覆蓋Window.softInputMode的行爲。從PopupWindow

private WindowManager.LayoutParams createPopupLayout(IBinder token) { 

    WindowManager.LayoutParams p = new WindowManager.LayoutParams(); 
    p.gravity = Gravity.LEFT | Gravity.TOP; 
    p.width = mLastWidth = mWidth; 
    p.height = mLastHeight = mHeight; 
    if (mBackground != null) { 
     p.format = mBackground.getOpacity(); 
    } else { 
     p.format = PixelFormat.TRANSLUCENT; 
    } 
    p.flags = computeFlags(p.flags); 
    p.type = mWindowLayoutType; 
    p.token = token; 
    /*mSoftInputMode is the private field which is by default equals 
     to WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED 
    */ 
    p.softInputMode = mSoftInputMode; 
} 

下面一段代碼,以便改變softInputMode你只需要調用PopupWindow

setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); 

公共方法而且也沒有必要記住以前的軟輸入法,因爲這種行爲會只適用於PopupWindow

相關問題