当我的片段开始时,我希望我的edittext成为焦点/让用户开始输入它.我能够通过requestFocus()获得焦点,但我无法让键盘显示出来.
我试过这两个:
edit = (EditText) view.findViewById(R.id.search);
edit.requestFocus();
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.showSoftInput(edit, 0);
Run Code Online (Sandbox Code Playgroud)
和
edit = (EditText) view.findViewById(R.id.search);
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.showSoftInput(edit, 0);
edit.requestFocus();
Run Code Online (Sandbox Code Playgroud)
如何让键盘显示EditText?
有很多关于查找显示/隐藏软键盘事件的帖子。我发现自己处于需要根据片段中的软键状态更改图标的情况。
我尝试实现 onMeasure,但无法在片段中覆盖它。是否有一种(相对)无痛的方法可以在我的片段中获得干净的显示/隐藏软键盘事件,或者我应该放弃发货?