Android:横向搜索工具 [英] Android: Search Tool in landscape orientation

查看:68
本文介绍了Android:横向搜索工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

状态栏中的搜索工具在横向时完全改变.

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

只有在搜索栏展开时才会发生.

It happens only when Search Bar is expanded.

请看截图.

编辑

代码:

@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"
    />

和菜单

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

推荐答案

终于修复了.如果您使用 widget SearchView,请将 android:imeOptions="actionSearch|flagNoExtractUi|flagNoFullscreen" 放在您的 SEARCHABLE xml 中.

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"
/>

这篇关于Android:横向搜索工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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