Softkeyboard在片段不显示的EditText
我有两个片段的简单应用程序。正确的片段所取代。一个EditText内部具有requestFocus的,但不显示键盘。
I have a simple application with two fragments. The right fragment is being replaced. An edittext inside has requestfocus, but does not show the keyboard.
在Android 4.2.2它正常工作,在2.3.x版本没有,无论是在模拟器还是真实的设备。在模拟器上,我可以用我的Windows键盘键入虽然软键盘没有显示。
On Android 4.2.2 it works fine, on 2.3.x it does not, neither in emulator nor on real device. On the emulator I can type with my windows keyboard although the soft keyboard is not showing.
我没有有意隐藏了键盘。显示的键盘采用以下code仅适用于4.2.x版。
I have not hidden the keyboard on purpose. Showing the keyboard with following code only works for 4.2.x.
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
任何暗示?
做更多的研究,我发现以下几点。
Doing more research I have found the following.
因为我需要将重点放在EditText上,我首先删除焦点,然后把它放回去:
Since I need the focus on the edittext, I first remove the focus and then put it back:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myFilter.clearFocus();
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
myFilter.requestFocus();
}
键盘没有显示,但一旦上的EditText用户点击,它出现。
The keyboard is not shown, but once the user clicks on the edittext, it comes up.
这仍然没有在2.3模拟器的工作,但它的工作原理在实际设备上。似乎是某种2.3的bug。
This still does not work on the 2.3 emulator, but it works on the real device. Seems to be some kind of 2.3 bug.