从片段导航到另一个隐藏键盘 [英] Hide keyboard when navigating from a fragment to another

查看:150
本文介绍了从片段导航到另一个隐藏键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个编辑文本的片段。当编辑文字pssed $ P $,正在显示的键盘。当$ P $上角pssed保存按钮,该应用程序返回到previous片段,但键盘依然存在。

I have a Fragment that contains an Edit Text. When the Edit Text is pressed, the keyboard is being shown. When pressed the Save button in the upper corner, the application returns to the previous fragment, but the keyboard persists.

导航到previous片段时,我想键盘被隐藏。

I would like the keyboard to be hidden when navigating to the previous fragment.

请注意,我试图这样的解决方案: 关闭/隐藏Android的软键盘

Please, note that I tried this solution: Close/hide the Android Soft Keyboard.

InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myView.getWindowToken(), 0);

我试图用这两个片段,在onCreate方法。

I tried to use this in both fragments, in the onCreate method.

我也试图隐藏软键盘的布局:

I also tried to hide the soft keyboard in the layout:

android:windowSoftInputMode="stateAlwaysHidden"

所有这些工作,很遗憾。

None of these worked, unfortunately.

我会贴一些照片,但我没有足够的声誉呢。 我想AP preciate任何建设性的帮助和意见,不要忘了,一个聪明人可以从中学到比傻瓜都能从一个明智的答案学到一个愚蠢的问题了。 :)

I would have posted some pictures, but I do not have enough reputation yet. I would appreciate any constructive help and opinion and do not forget that "A wise man can learn more from a foolish question than a fool can learn from a wise answer." :)

问候, 亚历山德拉

推荐答案

把code,隐藏了键盘的保存按钮,点击监听器,并使用此方法来隐藏键盘:

put the code that hides the keyboard in your save button click listener, and use this method to hide the keyboard:

public static void hideKeyboard(Context ctx) {
    InputMethodManager inputManager = (InputMethodManager) ctx
    .getSystemService(Context.INPUT_METHOD_SERVICE);

    // check if no view has focus:
     View v = ((Activity) ctx).getCurrentFocus();
     if (v == null)
        return;

    inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
 }

这篇关于从片段导航到另一个隐藏键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆