第一次搜索的时候无法隐藏软键盘,以后搜索就能隐藏了。这是为啥啊。。各位帮忙分析下啊。。具体代码:seachable.xml:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/search_title"
    android:includeInGlobalSearch="true"    android:searchSuggestAuthority="media"
    android:searchSuggestPath="external/audio/search"
    android:searchSuggestThreshold="3"
    android:searchSuggestIntentAction="android.intent.action.VIEW"
    android:searchSettingsDescription="@string/search_settings_description"
/>响应的QueryBrowserActivity:
在oncreate方法里面设置了隐藏软键盘。(会不会这地方设置不正确呢?)
InputMethodManager manager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);manager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.HIDE_NOT_ALWAYS);AndroidManifest.xml文件中也没有进行特殊设置:
 <activity android:name="QueryBrowserActivity"
         android:windowSoftInputMode="adjustPan"
                android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
                <action android:name="android.intent.action.MEDIA_SEARCH" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data
                android:name="android.app.searchable"
                android:resource="@xml/searchable"
            />
        </activity>

解决方案 »

  1.   

    各位DGDJ帮忙看下啊~~
    //seachable.xml:
    <searchable xmlns:android="http://schemas.android.com/apk/res/android"
      android:label="@string/search_title"
      android:includeInGlobalSearch="true"  android:searchSuggestAuthority="media"
      android:searchSuggestPath="external/audio/search"
      android:searchSuggestThreshold="3"
      android:searchSuggestIntentAction="android.intent.action.VIEW"
      android:searchSettingsDescription="@string/search_settings_description"
    />//响应的QueryBrowserActivity:
    //在oncreate方法里面设置了隐藏软键盘。(会不会这地方设置不正确呢?)
    InputMethodManager manager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);manager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.HIDE_NOT_ALWAYS);//AndroidManifest.xml文件中也没有进行特殊设置: <activity android:name="QueryBrowserActivity"
      android:windowSoftInputMode="adjustPan"
      android:theme="@android:style/Theme.NoTitleBar">
      <intent-filter>
      <action android:name="android.intent.action.SEARCH" />
      <action android:name="android.intent.action.MEDIA_SEARCH" />
      <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>
      <meta-data
      android:name="android.app.searchable"
      android:resource="@xml/searchable"
      />
      </activity>
      

  2.   

    Try thisprotected void hideInputMethod() {
    View view = this.getCurrentFocus();

            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
        }    protected void showInputMethod() {
    View view = this.getCurrentFocus();

            InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            if (imm != null) {
    imm.showSoftInput(view, 0);
            }
        }
      

  3.   

    在androidmainfest.xml添加一句代码就可以了<activity android:name="Test"
    android:windowSoftInputMode="adjustPan"></activity>
      

  4.   

    to jeffbao:
    昨天没看到。不好意思。呵呵~~
    周一去公司试试。。
    多谢啦。。android:windowSoftInputMode="adjustPan"设置过了,不管用。
      

  5.   


    HIDE_NOT_ALWAYS 源码中是这样解释的,显然第一次无法影藏 /**
         * Flag for {@link #hideSoftInputFromWindow} to indicate that the soft
         * input window should normally be hidden, unless it was originally
         * shown with {@link #SHOW_FORCED}.
         */
        public static final int HIDE_NOT_ALWAYS = 0x0002;改成这样试下
    InputMethodManager manager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);manager.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.HIDE_IMPLICIT_ONLY);
      

  6.   


    多谢 xinqiqi123:
    试过了InputMethodManager.HIDE_IMPLICIT_ONLY,貌似不管用,每次都隐藏不了。View view = this.getCurrentFocus();  InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
      if (imm != null) {
      imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
      }尝试过了,好像也不行。没辙了。
      

  7.   

    谢谢各位,最终问题是修改了QuickSearchBox应用中的方法。
    当跳转到其他应用时,把软键盘隐藏就ok了。