0

嗨,我在我的 tabhost 中使用了四个选项卡,名为 TabOne、TabTwo、TabThree、TabFour。

在 TabOne 中,我有 editext 进行搜索选项,当我按下编辑文本时,它会显示键盘。但是没有关闭键盘当我移动到 TabTwo 时,键盘仍然显示。我不希望键盘在 TabTwo、TabThree、TabFour 中启用。因为所有其他三个选项卡都没有 edittext 选项。

现在我的问题是如何在单击其他选项卡时隐藏键盘。

我尝试了以下方法,

oncreate在TabB的方法中添加以下代码

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

在 Android 清单文件中添加以下 xml 标记

     android:windowSoftInputMode="stateAlwaysHidden"

请指导我解决这个问题。

4

4 回答 4

1

失去焦点时隐藏编辑文本。

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
   @Override
   public void onFocusChange(View v, boolean hasFocus) {
    if (!hasFocus) {
        hideKeyboard();
    }
   }

});

void hideKeyboard() {
   InputMethodManager imm = (InputMethodManager)  getSystemService(Activity.INPUT_METHOD_SERVICE);
   imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
于 2012-10-08T14:08:04.120 回答
0

请看这个答案

启用软键盘

inputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

并禁用软键盘

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
于 2012-10-08T14:14:22.877 回答
0

这对我有用:

在单击特定选项卡时触发的 Activity 中,我在 onCreate 中使用了它:

inputSearch.setOnFocusChangeListener(new View.OnFocusChangeListener() {
           @Override
           public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(inputSearch.getWindowToken(), 0);
            }
           }});

在 AndroidManifest.xml 中,我将以下内容添加到我的 MainActivity(定义了所有选项卡的位置):

android:windowSoftInputMode="stateAlwaysHidden"
于 2013-05-18T20:00:07.223 回答
0
this.getWindow().setSoftInputMode(
    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

这条线将为您工作。看一下这个。

于 2013-11-23T06:21:20.480 回答