我有两个片段,每个片段都有编辑文本。所以我想要实现的是每次创建片段时,焦点都在于编辑文本和键盘。另外,当我替换这些片段时,我不想隐藏并再次显示键盘,但是通过我的解决方案,这就是现在正在发生的事情。
我将此属性设置为activity:
android:windowSoftInputMode="adjustResize|stateAlwaysVisible|stateUnchanged"
每个片段都在onResume()中调用此方法:
private void focusOnEditText() {
mTextInputEditText.setFocusableInTouchMode(true);
mTextInputEditText.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mTextInputEditText, InputMethodManager.SHOW_IMPLICIT);
}
答案 0 :(得分:0)
阅读文档 toggleSoftInput
private void focusOnEditText() {
mTextInputEditText.setFocusableInTouchMode(true);
mTextInputEditText.requestFocus();
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}