0

嗨伙计们如何在将一个视图寻呼机更改为另一个视图寻呼机时隐藏软键盘

问题在于视图寻呼机有四个选项卡,当我单击搜索编辑文本时,第一个选项卡具有搜索选项,然后在我单击另一个选项卡后。软键盘在下一个选项卡中可见。

如何解决这个问题,我试过这种方式它不起作用

((InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE))
        .toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);

帮助

4

3 回答 3

0

只需在您的标签AndroidManifest下添加此属性:activity

    <activity
        android:name="com.example.myApp.MyActivity"
        android:windowSoftInputMode="stateHidden" >
    </activity>
于 2013-06-19T06:20:21.413 回答
0

试试下面的代码。

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

这里的any_focusable_view_reference意思EditText是有焦点的东西。

于 2013-06-19T06:30:41.280 回答
0

刚刚将 setOnFocusChangeListener 添加到 Edittext ,然后它工作正常。

EditText editTextProfileName = (EditText) view
                    .findViewById(R.id.nameEditText);

            editTextProfileName.setOnFocusChangeListener(new OnFocusChangeListener() {

                public void onFocusChange(View v, boolean hasFocus) {
                      if (!hasFocus) {
                            hideKeyboard();
                        }
                }

                private void hideKeyboard() {
                    if (editTextProfileName != null) {
                        InputMethodManager imanager = (InputMethodManager) getActivity()
                                .getSystemService(Context.INPUT_METHOD_SERVICE);
                        imanager.hideSoftInputFromWindow(editTextProfileName.getWindowToken(), 0);

                    }

                }
            });

谢谢

于 2013-08-29T12:54:01.233 回答