感谢阅读。
我遇到了一个奇怪的问题:我的应用程序行为是这样的,当 Activity
启动时,我在一个 EditText
上调用了 requestFocus()
并显示软键盘。
然而,当我按下后退按钮以关闭键盘,并点击 EditText
,我再也无法弹出键盘。唯一的解决方法是重新启动 Activity
。
这是我的代码:
EditText editText = (EditText) findViewById(R.id.editText);
editText.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if(imm != null) {
imm.toggleSoftInput(0, 0);
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
}
以下是我的 XML:
<EditText android:id="@+id/editText"
android:layout_width="wrap_content"
android:imeOptions="actionSearch" android:hint="Test Hint"
android:layout_height="wrap_content" android:layout_centerHorizontal="true"
android:maxLength="30">
</EditText>
任何帮助都将不胜感激!
谢谢!