Android: Search Tool in landscape orientation

房东的猫 提交于 2019-12-24 12:08:21

问题


The Search Tool in StatusBar changes completely when in Landscape orientation.

It happens only when Search Bar is expanded.

Please see the screenshots.

EDIT

CODE:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.action_menu, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    int options = searchView.getImeOptions();
    searchView.setImeOptions(options| EditorInfo.IME_FLAG_NO_EXTRACT_UI);

    searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName()) );
    searchView.setIconified(true);
    searchView.clearFocus();

    return true;
}

XML:

    <?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
     android:label="@string/app_name"
     android:searchSuggestAuthority="Search in a Collection/Book or Favorites"
    />

And menu

<item
    android:id="@+id/search"
    app:actionViewClass="android.support.v7.widget.SearchView"
    app:showAsAction="ifRoom"
    android:title="Search in a Collection/Book or Favorites"/>

回答1:


Finally fixed it. Put android:imeOptions="actionSearch|flagNoExtractUi|flagNoFullscreen" in your SEARCHABLE xml if you are using widget SearchView.

<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
    android:label="@string/app_name"
    android:imeOptions="actionSearch|flagNoExtractUi|flagNoFullscreen"
/>


来源:https://stackoverflow.com/questions/46263084/android-search-tool-in-landscape-orientation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!