I've implemented a simple EditText that provides a Done button to hide the keyboard and upon rotating to landscape it does not present a full screen dialog for the EditText. But there's a problem. When I tap Done to dismiss the keyboard then I rotate the device to landscape, the keyboard appears. If I dismiss it again then rotate to portrait the keyboard appears yet again.
How can I preserve the keyboard visibility state upon rotation - if it was hidden before rotation then don't present it after rotation, but if it was visible before rotation then present it after rotation?
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/editText1"
android:inputType="text"
android:imeOptions="flagNoFullscreen|actionDone" />
I tried setting android:descendantFocusability="beforeDescendants"
and android:focusableInTouchMode="true"
in the parent container (RelativeLayout), but that didn't affect this behavior.
There are two options.. In your
onCreate()
method try these optionsOption 1.
Option 2
This option sets the focus back to the first focusable view in the activity.
EDIT:
Option 2 will not work if your edittext it self is the first focusable view in your activity as
clearFocus
sets the focus back to first focusable view in your activity.Usage of Option 1:
there are many ways to do but i give you 2
1 overide onConfigurationChange method in there at the time of configuration change see if keyboard is open or not and you can act according by saving the value of it an boolean and after onConfigurationChange is changes use that boolean value to show or hide keyboard.
2 Another way if you have not implemented onConfigurationChange method is saving status in onSaveInstanceState and retrieving it in onRestoreInstanceState like below.