2

所以我有一個使用windowSoftInputMode="adjustPan"的活動,我有一個OnPreDrawListenerEditText調用:顯示與InputMethodManager手動軟鍵盤不調整窗口

editText.requestFocus(); 
inputManager.showSoftInput(editText, 0); 

預期其中一期工程和推Activity最多爲EditText騰出空間。但是,如果我使用後退按鈕(將窗口移回原始位置)關閉鍵盤,則再次觸摸EditText以顯示鍵盤,鍵盤顯示,但窗口不調整。

我甚至嘗試添加一個OnClickListenerEditText並再次調用相同的兩個呼叫:

editText.requestFocus(); 
inputManager.showSoftInput(editText, 0); 

但窗口不轉動,直到我關閉該窗口,並再次顯示它。有什麼建議麼?

+0

你試過在onBackPressed上調用hideSoftInputFromWindow,只是想要得到你想要的東西 – Naveen 2013-03-08 03:12:44

+0

不幸的是,似乎沒有任何效果。 – kcoppock 2013-03-08 03:17:16

回答

0

所以這不是一個解決方案的問題,但它是我最終解決的解決方法。我創建的LinearLayout一個子類的IME接收之前攔截後退按鈕按下:

public class IMEInterceptLinearLayout extends LinearLayout { 
    //For some reason, the event seems to occur twice for every back press 
    //so track state to avoid firing multiple times 
    private boolean notifiedListener = false; 
    private OnBackPressedPreIMEListener listener; 

    public IMEInterceptLinearLayout(Context context) { 
     super(context); 
    } 

    public IMEInterceptLinearLayout(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public IMEInterceptLinearLayout(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    public void setOnBackPressedPreIMEListener(OnBackPressedPreIMEListener listener) { 
     this.listener = listener; 
    } 

    private void fireOnBackPressedPreIME() { 
     if(listener != null && !notifiedListener) { 
      listener.onBackPressedPreIME(); 
      notifiedListener = true; 
     } 
    } 

    @Override 
    public boolean dispatchKeyEventPreIme(KeyEvent event) { 
     if(event.getKeyCode() == KeyEvent.KEYCODE_BACK) { 
      fireOnBackPressedPreIME(); 
      return true; 
     } else return super.dispatchKeyEventPreIme(event); 
    } 

    public interface OnBackPressedPreIMEListener { 
     public void onBackPressedPreIME(); 
    } 
} 

然後從那裏我剛剛註冊我的窗口作爲佈局的監聽器,並關閉窗口,當我收到鍵盤該事件在窗口可見時不允許鍵盤被解除。

0

我認爲這三個步驟將解決您的問題。

1)在清單文件變化windowSoftInputMode = 「adjustPan」 到windowSoftInputMode = 「adjustResize」

2)你正在使用的EditText佈局,THA改變親佈局ScroolView。

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <EditText 
     android:id="@+id/edittextview" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:inputType="textFilter" 
     android:padding="10dp" 
     android:imeOptions="actionDone" 
     android:scrollbars="vertical" 
     android:textSize="14sp" /> 
</ScrollView> 

3)要明確地顯示鍵盤,以避免「取消鍵盤與後退按鈕和窗口,不調整」,在EDITTEXT 的onclick寫

edittext.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
       InputMethodManager m = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
       if (m != null) { 
        m.toggleSoftInput(0, InputMethodManager.SHOW_IMPLICIT); 
        edittext.requestFocus(); 
       } 
      } 
     }); 

希望這將解決您的問題。

+0

謝謝,明天我會給第三個選項一個嘗試;改變爲'ScrollView'和'adjustResize'並不是期望的行爲;它需要平移,而不是調整窗口的大小。 – kcoppock 2013-03-08 03:58:32

+0

不幸的是,它並沒有幫助,同樣的問題仍然存在。 – kcoppock 2013-03-12 08:12:00