267

On Android devices that use soft keyboards, I want to prevent the fullscreen keyboard editing view (shown below) from appearing when in landscape mode (i.e. I want to see only the soft keyboard itself and my view behind it).

I assume this can be achieved using the setExtractViewShown(false) method on InputMethodService, but I am unable to access the default instance of this and do not want to implement a custom input method.

Android fullscreen editing view

Edited to add: the view to which input is going is not a TextView (it's a View with a custom InputConnection implementation), so android:imeOptions="flagNoExtractUi" won't work here.

jnic
  • 8,695
  • 3
  • 33
  • 47
  • Let try to see it. It's good for you. [Look to this one][1] [1]: http://stackoverflow.com/questions/8648401/how-to-open-only-half-keyboard-in-landscape-mode – sonida Jun 24 '13 at 02:33
  • i have a similar problem :( you might have any idea? http://stackoverflow.com/questions/36914290/android-soft-keyboard-in-a-fullscreen-surface-view – Yesyoor Apr 28 '16 at 12:38
  • 2
    how to apply this throughout the whole app.We are not going to add the attribute-value in every edittext in xml. – Vikas Pandey Sep 12 '16 at 10:05
  • 5
    Many of the answers below recommend using `flagNoExtractUi` or `IME_FLAG_NO_EXTRACT_UI`. However,in the documentation for [`IME_FLAG_NO_EXTRACT_UI`](https://developer.android.com/reference/android/view/inputmethod/EditorInfo#IME_FLAG_NO_EXTRACT_UI), which corresponds to `flagNoExtractUi`, it states that "Using this flag is discouraged and it may become deprecated in the future", so `flagNoFullscreen` is the recommended option. – ThomasW Feb 27 '19 at 07:51

11 Answers11

186

I finally answered my own question:

The extract UI (i.e. the fullscreen editing mode) can be disabled at the point at which the input connection is hooked up:

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {

    outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI;

    // etc.
}
jnic
  • 8,695
  • 3
  • 33
  • 47
  • 227
    just simply put in your xml file android:imeOptions="flagNoExtractUi" –  Apr 27 '11 at 04:28
  • 1
    jnic, where did you do that override at in the soft keyboard code? SoftKeyboard.java? I tried the same override and error'd out. –  Apr 27 '11 at 05:08
  • hey jnic. I am doing it in the same way but its not working for me.. i am still getting fullscreen keyboard editing view. – Swati Jul 11 '12 at 09:00
  • 16
    You'll probably want to add the flag to the options instead of overriding what ever options were being passed in like this: `outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI;` – ObsidianX Dec 04 '12 at 00:31
  • @Swati I think he means to put this method under every `EditText` `View` you want the full screen styled to be disabled. – Yulong Feb 28 '13 at 01:20
  • 2
    @user726518 how to apply this attribute on the searchbox item in action bar ? – Menna-Allah Sami May 15 '14 at 13:27
  • It's enough to just add android:imeOptions="flagNoExtractUi" inside a particular EditText element. – goRGon Oct 13 '14 at 22:44
  • better to use flagNoFullscreen as it does not lock editing options and drag-and-drop on N between activities – Penzzz Jun 21 '16 at 11:33
  • There is not exact implementation. where should it be used and what should return in method. – vivek Dec 12 '16 at 06:32
  • 1
    The only thing worked when using custom View to handle keyboard. Thanks! – Hermandroid Mar 27 '17 at 20:12
131

To do that, navigate to activity xml and paste android:imeOptions="flagNoExtractUi" in your code. But where should it be pasted? Have look at code of example activity xml and look at EditText:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"         
    >

    <EditText
        android:imeOptions="flagNoExtractUi"

        android:id="@+id/etTextInAct"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >   
        <requestFocus />
    </EditText>

</LinearLayout>
      

If you want more customisation options for the keyboard see http://developer.android.com/guide/topics/ui/controls/text.html

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
pbaranski
  • 22,778
  • 19
  • 100
  • 117
  • 3
    FYI `EditorInfo.IME_FLAG_NO_EXTRACT_UI` suggests using `IME_FLAG_NO_FULLSCREEN` instead. – Saket Sep 21 '20 at 22:26
67

add the property android:imeOptions="flagNoExtractUi" to each EditText in your XML file.

Michael Yaworski
  • 13,410
  • 19
  • 69
  • 97
  • 1
    This answer is too short and doesn't meet SO quality standards. Please improve it adding some additional explanations, so that it will be useful for the community and not only for the OP. – LorenzoDonati4Ukraine-OnStrike Nov 03 '13 at 22:16
  • 32
    @LorenzoDonati it's exactly what you have to do... it's a very simple answer because the solution is very simple and it's just a different way of doing it than the answers above. Also, answers can't be "too short" unless they don't answer the question, IMO. – Michael Yaworski Nov 03 '13 at 22:19
  • 1
    Sorry, but this is not what the SO community thinks about it. The answers should not be limited to solve the OP's problem, they should be great answers in general. See [this](http://meta.stackexchange.com/a/138740/232931) and [this](http://meta.stackexchange.com/a/156951/232931), for example. – LorenzoDonati4Ukraine-OnStrike Nov 03 '13 at 22:26
  • 22
    @LorenzoDonati it is a *very* specific question with only one end result (but multiple ways to solve it). My answer is an addition to the other answers on this page. **ALL** of the answers on this page are only limited to the "OP's problem" because that's the only kind of answer that can be written. Like I said, it's specific and simple. – Michael Yaworski Nov 03 '13 at 22:38
  • 2
    finally, i found the answer. thank you so much @mike yaworski – Drx Apr 29 '14 at 05:54
  • @LorenzoDonati The question states that `android:imeOptions="flagNoExtractUi" won't work here.` That would have been a much better platform than attempting to suggest readers are subjected to unnecessary rambling. – Abandoned Cart May 18 '19 at 22:01
56

The answer above helped me figure out the solution for dynamically added EditTexts:

editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
Abdo
  • 13,549
  • 10
  • 79
  • 98
44

Use android:imeOptions="flagNoFullscreen" to achieve that feature.

ridoy
  • 6,274
  • 2
  • 29
  • 60
  • 1
    nice and better approach to write in xml. Works for me. Thanks – Ahesanali Suthar Apr 26 '16 at 05:44
  • 3
    Note that in the documentation for [`IME_FLAG_NO_EXTRACT_UI`](https://developer.android.com/reference/android/view/inputmethod/EditorInfo#IME_FLAG_NO_EXTRACT_UI), which corresponds to `flagNoExtractUi`, it states that "Using this flag is discouraged and it may become deprecated in the future", so `flagNoFullscreen` is the recommended option. – ThomasW Feb 27 '19 at 07:49
14

Also, if you want to combine multiple imeOptions programaticaly, you can use the | syntax.

For example, in order to disable the fullscreen edit view in landscape and replace "Next" key by "OK" (ACTION_DONE) in keyboard, you can use:

editText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
Maxime Ancelin
  • 870
  • 9
  • 11
11

My solution:

android:imeOptions="flagNoExtractUi|flagNoFullscreen"
Pang
  • 9,564
  • 146
  • 81
  • 122
dastan
  • 892
  • 10
  • 17
9

If you're modifying the IME directly you can prevent it from ever displaying an ExtractedView by overriding onUpdateExtractingVisibility:

@Override
public void onUpdateExtractingVisibility(EditorInfo ei) {
    ei.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI;
    super.onUpdateExtractingVisibility(ei);
}
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
ObsidianX
  • 529
  • 5
  • 4
6

I know it's a little bit late but for anyone who is still interested, here is my solution : In my case I had a landscape Activity containing an EditText at top of it and I needed to implement autocomplete feature in this search Activity, which the overlapping keyboard caused an issue that the user could not see result of RecyclerView. So I ended up having this EditText in my layout:

<EditText
  android:layout_width="match_parent"
  android:layout_height="?actionBarSize"
  android:id="@+id/main_search_et"
  android:imeOptions="actionSearch|flagNoExtractUi"
  android:inputType="text"  />

Cheers!

2

You can use :

android:imeOptions="flagNoFullscreen" 

in your edittext

Thientvse
  • 1,753
  • 1
  • 14
  • 23
0

You can call to hide soft keyboard and clear focus from searchview.

public void hideKeyboard(View view) {
    InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

super.clearFocus();
Eduard Malakhov
  • 1,095
  • 4
  • 13
  • 25