EditText获取焦点时输入法闪一下然后消失

版权声明: https://blog.csdn.net/ShadowySpirits/article/details/79561776

场景

点击搜索按钮时,出现EditText同时收起下方List。此时EditText获取焦点但是输入法闪出来一下就消失。

解决方法

在AndroidManifest.xml的对应activity中加入:

android:windowSoftInputMode="adjustPan"


或者在activity中修改一下输入模式(输入模式的详细介绍以及键盘面板的其他坑详见:链接):

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);


然后修改EditText:

mEditSearch.requestFocus();
InputMethodManager inputMethodManager =(InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(mEditSearch, InputMethodManager.SHOW_IMPLICIT);


完美解决!

猜你喜欢

转载自blog.csdn.net/ShadowySpirits/article/details/79561776
今日推荐