更改标签时如何隐藏软键盘? [英] How do I hide the soft keyboard when changing tabs?

查看:27
本文介绍了更改标签时如何隐藏软键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我没有说清楚.我需要的是每当我替换我所在的片段时隐藏软键盘的方法.我该怎么做?

让我保持简单.我在 Tab Fragment 1.2 中有一个 EditText 框,它在按下时显然会打开软键盘.更改选项卡时如何隐藏它?我在我的 onTabSelected() 中尝试了以下似乎没有做任何事情

Let me keep this simple. I have an EditText box in Tab Fragment 1.2 which obviously opens op the Soft keyboard when pressed. How do I hide this when the tab is changed? I tried the following in my onTabSelected() which doesn't seem to do anything

getWindow().setSoftInputMode(
                  WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

我现在什么都试过了.到目前为止,我找到的所有建议解决方案都没有以任何方式帮助我.

I've tried everything now. None of the suggested solutions I've located so far are helping me in any way.

推荐答案

您可以以编程方式使用,捕获设备屏幕上活动活动的视图.

programmatically you could use, capturing the view of the active activity on the screen of the device.

public final void onTabReselected(Tab tab, FragmentTransaction fragmentTransaction) {
        View focus = getCurrentFocus();
        if (focus != null) {
            hiddenKeyboard(focus);
        }
    }
public final void onTabselected(Tab tab, FragmentTransaction fragmentTransaction) {
        View focus = getCurrentFocus();
        if (focus != null) {
            hiddenKeyboard(focus);
        }
    }
public final void onTabUnselected(Tab tab, FragmentTransaction fragmentTransaction) {
        View focus = getCurrentFocus();
        if (focus != null) {
            hiddenKeyboard(focus);
        }
    }

private void hiddenKeyboard(View v) {
        InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        keyboard.hideSoftInputFromWindow(v.getWindowToken(), 0);
    }

这篇关于更改标签时如何隐藏软键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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