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

相关问题