Show soft keyboard when the device is landscape mode
Asked Answered
A

4

9

This code seems not to work in Landscape mode:

EditText destinationSearch = (EditText) findViewById(R.id.destinationSearch); 

destinationSearch.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(destinationSearch, InputMethodManager.SHOW_IMPLICIT);

Is there any solution to show the soft keyboard in Landscape mode ?

Abrahamabrahams answered 21/1, 2011 at 17:18 Comment(1)
Seems to work with SHOW_FORCE flag :DAbrahamabrahams
M
12

You need to use show forced

InputMethodManager imm;
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
imm.showSoftInput(this.editText,InputMethodManager.SHOW_FORCED);
Meander answered 25/1, 2011 at 13:59 Comment(1)
Why do you need to toggleSoftInput with HIDE_IMPLICIT_ONLY?Aniline
C
3

The reason is that landscape mode most often put soft keyboard in a new full screen window. As Bakih said, force will work but the full screen window have more effects and so do SHOW_FORCED.

I prefer adding

    <item name="android:imeOptions">flagNoFullscreen</item>

to my EditTextStyle so I can always catch onGlobalLayout() and so on. Now you can use SHOW_IMPLICIT. Just make sure your UI looks good in such a small area and remove autoCorrect if not needed.

Cerenkov answered 19/2, 2015 at 23:18 Comment(0)
T
0
EditText editText = (EditText)findViewById(R.id.editText);

editText.setFocusableInTouchMode(false);

final Context context = this;

editText.setOnClickListener(new OnClickListener() {

    @Override 
    public void onClick(View v) {

        v.requestFocusFromTouch();

        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(v, InputMethodManager.SHOW_FORCED);

    } 
}); 
Teeterboard answered 6/6, 2015 at 18:2 Comment(1)
You might find it useful to add an explanation to your answer so readers can see why your answer is the best, rather than just post code alone. You can add to your answer by pressing the "edit" button.Scarabaeus
J
0

Simpler XML changes answer https://mcmap.net/q/108634/-disabling-the-fullscreen-editing-view-for-soft-keyboard-input-in-landscape

 <EditText   
        android:id="@+id/txtInLandscapeVw"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:imeOptions="flagNoExtractUi">   
        <requestFocus />
    </EditText>

So add

android:imeOptions="flagNoExtractUi

and

<requestFocus />

Jeggar answered 15/10, 2020 at 18:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.