所以我有一个使用 windowSoftInputMode="adjustPan"
的 Activity,并且我有一个 OnPreDrawListener
用于 EditText
,它调用:
editText.requestFocus();
inputManager.showSoftInput(editText, 0);
它按预期工作并将 Activity
向上推以为 EditText
腾出空间。但是,如果我用后退按钮关闭键盘(将窗口平移回原始位置),然后再次触摸 EditText
以显示键盘,键盘会显示,但窗口不会调整.
我什至尝试将 OnClickListener
添加到 EditText
并再次调用相同的两个调用:
editText.requestFocus();
inputManager.showSoftInput(editText, 0);
但是在我关闭窗口并再次显示它之前,窗口不会平移。有什么建议吗?
最佳答案
我认为这三个步骤将解决您的问题。
1)在 list 文件更改窗口SoftInputMode="adjustPan" 到 windowSoftInputMode="adjustResize"
2) 您用于 EditText 的布局,将父布局更改为 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中点击写入
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();
}
}
});
希望这能解决您的问题。
关于android - 使用 InputMethodManager 手动显示软键盘不会调整窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15285923/