14

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

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?

13KZ
  • 1,295
  • 5
  • 24
  • 43
  • 1
    Possible duplicate of http://stackoverflow.com/questions/4336762/disabling-the-fullscreen-editing-view-for-soft-keyboard-input-in-landscape – yahya Jul 20 '15 at 13:35
  • I'm using a searchview programmatically. I can't invoked onCreateInputConnection and EditorInfo flags are not helpful – 13KZ Jul 20 '15 at 13:48

3 Answers3

29

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

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.

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():

Java:

search.setImeOptions(options|EditorInfo.IME_FLAG_NO_EXTRACT_UI);

Kotlin:

search.setImeOptions(search.imeOptions or 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.

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;
}

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

Result without the call to setImeOptions():

Before

Result with the call to setImeOptions():

enter image description here

Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
  • 1
    This solution works for me. Thanks you so much @Daniel. – 13KZ Jul 22 '15 at 08:18
  • Setting this in the xml (as written in other answers) "may" not work as is because of how you setup things. Therefore set it in code like in this answer if xml versions do not work for you in all cases. – frankish Apr 06 '20 at 07:38
  • 1
    This is actually still valid, In case you are looking for the Kotlin way: `search.setImeOptions(search.imeOptions or EditorInfo.IME_FLAG_NO_EXTRACT_UI)` – Romina Liuzzi Jun 17 '21 at 21:46
  • @RominaLiuzzi I updated the answer, thank you! – Daniel Nugent Jun 17 '21 at 22:39
1

Another alternative to the code is to add the property in the searchView xml, it is useful for APIs less than 16:

<SearchView
    android:imeOptions="flagNoExtractUi" />
1

Same idea as above written but without SearchView, only using searchable XML

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
 ...
 android:imeOptions="actionSearch|flagNoExtractUi"
 ...
</searchable>
Andrii
  • 11
  • 3