显示和隐藏软板不起作用

阿摩司

不确定是否相关,但我将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);

布局是这样,包括相关字段的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>

当打开此片段时,光标应在其应有的位置,但键盘不在此处。仅当在字段内点击时,它们才会出现。

另一个问题与第一个问题相反。在另一个片段上,无论片段如何,我都想在片段打开时隐藏键盘。这样做的原因是,用户可以在关闭另一个片段后打开该片段,在该片段中显示了键盘,因此我想确保将其关闭,请注意,我不知道是否显示了键盘,我希望它如果已经关闭,则保持关闭;如果已经打开,则关闭。我在这个片段中只有一个ListView,所以我做了以下工作:

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);

但它拒绝对键盘产生任何影响,并且保持打开状态。

我究竟做错了什么?

比格勒

尝试调用的代码onResume()post()它作为一个Runnable如果你FragmentDialogFragment,呼吁getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);onCreateView()应该足够了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章