Android软键盘未触发
Android softkeyboard not triggerring
我的屏幕上有多个 EditText,其中一个被聚焦。软键盘不会在屏幕弹出时立即触发。我希望软键盘在屏幕弹出时立即触发。如果我不实现 onFocusChangeListener(),它会很好地工作。但是我需要 onFocusChangeListener() 来检测哪个 editText 被聚焦。我试过设置 setFocusable(true) 和 setFocusableInTouchMode(true)。我也不想修改 android:windowSoftInputMode 属性 in AndroidMenifest.xml。我有以下标准:
- onFocusChangeListener 实现(检测哪个 edittext 获得焦点)
- AndroidMenifest.xml
没有修改
这是我的代码片段
final InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
mInput.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
mIsFocused = hasFocus;
if(hasFocus)
inputMethodManager.showSoftInput(mInput, InputMethodManager.SHOW_IMPLICIT);
}
});
有什么建议吗?
您可以通过编程方式打开软键盘
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
您可以尝试使用 inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
。
来源:Whosebug post
我的屏幕上有多个 EditText,其中一个被聚焦。软键盘不会在屏幕弹出时立即触发。我希望软键盘在屏幕弹出时立即触发。如果我不实现 onFocusChangeListener(),它会很好地工作。但是我需要 onFocusChangeListener() 来检测哪个 editText 被聚焦。我试过设置 setFocusable(true) 和 setFocusableInTouchMode(true)。我也不想修改 android:windowSoftInputMode 属性 in AndroidMenifest.xml。我有以下标准:
- onFocusChangeListener 实现(检测哪个 edittext 获得焦点)
- AndroidMenifest.xml 没有修改
这是我的代码片段
final InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
mInput.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
mIsFocused = hasFocus;
if(hasFocus)
inputMethodManager.showSoftInput(mInput, InputMethodManager.SHOW_IMPLICIT);
}
});
有什么建议吗?
您可以通过编程方式打开软键盘
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
您可以尝试使用 inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
。
来源:Whosebug post