Android
Android

Reputation: 3878

Keyboard issues arising on orientation change

In my app I am using various edit text and text view and list view. Now my problem is my keyboard appears again on orientation change. Ideally when user minimize the keyboard, it should be in minimized state when device is tilted. But it reappears. How do we handle this situation.

My other problem is one of my edit text is some what at the end of screen. When keyboard appears, it hides the edit text. so user is not able to see what he is typing. What is the ideal way to handle this. thanks.

Upvotes: 12

Views: 6793

Answers (5)

running-codebase
running-codebase

Reputation: 998

I found the following documentation to be helpful in understanding the various flags associated with the soft keyboard: https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

Upvotes: 0

Patrick
Patrick

Reputation: 1387

I had this same problem. To keep the keyboard from re-appearing on rotation when you have TextViews, you must do 2 things-

  1. Make sure the TextView doesn't have the focus. Even after hiding the keyboard, a TextView can still be focused. Try calling

    textView.clearFocus()
    

    and you should be able to see the difference in the TextView.

  2. Make sure there is another view before it (like a parent LinearLayout, or even just a LinearLayout with 0 width and 0 height) which has these properties-

    android:focusable="true"
    android:focusableInTouchMode="true"
    

Upvotes: 3

Android
Android

Reputation: 3878

Solution to all problem is this line android:windowSoftInputMode="stateUnchanged|adjustResize"

"stateUnchanged" will make the state of keyboard same as it was in earlier state. Either hidden or visible.

"adjustResize" will make your edit text visible.

Hope this helps.!!!

Edit

This need to be added in android manifest file.

Upvotes: 34

Antrromet
Antrromet

Reputation: 15424

Try adding this code in your Activities properties in the manifest

 android:windowSoftInputMode="stateHidden|adjustPan"

Like

 <activity
            android:name=".MyActivity"
            android:windowSoftInputMode="stateHidden|adjustPan" >

This should take care of both your problems

Upvotes: 2

Rajeev N B
Rajeev N B

Reputation: 1363

For the Second Question : You can set your layout to ScrollView to avoid hiding of edittext on Keyboard appears. Put your entire layout in a ScrollView.

Upvotes: 0

Related Questions