有没有办法避免在横向上使用全屏SearchView /键盘? [英] Is there a way to avoid having fullscreen SearchView/Keyboard on landscape?

查看:188
本文介绍了有没有办法避免在横向上使用全屏SearchView /键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试避免在横向上进行全屏键盘编辑以访问建议。

I'm trying to avoid having fullscreen keyboard editing on landscape in order to access to the suggestions.

我已经阅读了很多线程,解释说我必须添加像 flagNoFullscreen 和/或 flagNoExtractUi 这样的EditorInfo标志。 。

I already read a lot of threads explaining that I have to add EditorInfo flags like flagNoFullscreen and/or flagNoExtractUi.

我以编程方式添加了它们但没有真正帮助。

I added them programmatically but not really helpful.

有没有办法解决这个问题?

Is there a way to figure this out?

推荐答案

我花了一段时间才想出这个,但实际上很简单。

It took me a while to figure this one out, but it's actually quite simple.

最初我创建了一个扩展SearchView类的自定义类,并使用了 onCreateInputConnection()覆盖,但是我无法以这种方式工作。

Initially I created a custom class that extended the SearchView class, and used a onCreateInputConnection() override, however I couldn't get it working that way.

我最终以更加简单的方式使用它,只添加了两行代码。

I eventually got it working in a much more simple way, with just two added lines of code.

您只需要调用 search.getImeOptions()来获取当前配置,然后使用SourceInfo.IME_FLAG_NO_EXTRACT_UI 拨打 setImeOptions()

You just need to call search.getImeOptions() to get the current configuration, and then "or" the result with EditorInfo.IME_FLAG_NO_EXTRACT_UI with a call to setImeOptions():

search.setImeOptions(options|EditorInfo.IME_FLAG_NO_EXTRACT_UI);

如果您没有或使用现有选项,那么您就不会得到搜索右下方的完成按钮,您只需获得完成按钮。

If you don't "or" with the existing options, then you don't get the "Search" completion button in the lower right, you just get a "Done" button instead.

这是完整的 onCreateOptionsMenu()覆盖我曾经测试过(我在xml中使用了SearchView,但即使你没有从xml中膨胀你的SearchView,这个解决方案也适合你):

Here is the full onCreateOptionsMenu() override I used to test (I used a SearchView in the xml, but this solution should work for you even if you're not inflating your SearchView from xml):

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.menu_main, menu);

    SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    SearchView search = (SearchView) menu.findItem(R.id.action_search).getActionView();

    SearchableInfo si = manager.getSearchableInfo(getComponentName());

    //Here is where the magic happens:
    int options = search.getImeOptions();
    search.setImeOptions(options|EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    //!!!!!!!!!!!

    search.setSearchableInfo(si);

    search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            return true;
        }

    });
    return true;
}

这是我在menu_main.xml中用于SearchView的xml:

Here is the xml I used for the SearchView in menu_main.xml:

<item android:id="@+id/action_search"
        android:title="Search"
        android:icon="@android:drawable/ic_menu_search"
        app:showAsAction="always"
        app:actionViewClass="android.support.v7.widget.SearchView"
        />

没有调用的结果setImeOptions()

调用的结果setImeOptions()

这篇关于有没有办法避免在横向上使用全屏SearchView /键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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