Android 显示和隐藏软keboard不起作用

Android 显示和隐藏软keboard不起作用,android,android-softkeyboard,Android,Android Softkeyboard,不确定是否相关,但我使用的是LG G3和Android 4.4.2 我想让键盘显示一个片段,所以我做了以下操作: txtContact = (EditText) rootView.findViewById(R.id.txtContact); InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFrom

不确定是否相关,但我使用的是LG G3和Android 4.4.2

我想让键盘显示一个片段,所以我做了以下操作:

txtContact = (EditText) rootView.findViewById(R.id.txtContact);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txtContact.getWindowToken(), InputMethodManager.SHOW_IMPLICIT);
lv = (ListView) rootView.findViewById(android.R.id.list);
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(lv.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
布局如下,包括相关字段的requestFocus:

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textMultiLine"
        android:ems="10"
        android:lines="10"
        android:layout_margin="10dp"
        android:id="@+id/txtContact">

        <requestFocus />
    </EditText>
但它拒绝对键盘产生任何影响,并且仍然保持打开状态


我做错了什么?

尝试在
onResume()
post()
中调用代码,将其作为
Runnable

如果
片段
是一个
对话框片段
,则调用
getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT\u INPUT\u STATE\u VISIBLE)onCreateView()
中的code>应该足够了。

当您想显示键盘时,为什么要调用
hideSoftInputFromWindow()
?考虑使用<代码> StuffStutPoT()/<代码>。我将它更改为imm。但它没有效果,键盘没有显示在哪里?我在创建片段视图时调用的showSoftInput在
onResume()
post()
中尝试将该代码作为
Runnable
运行。