I want to automatically show the soft-keyboard when an EditText
is focused (if the device does not have a physical keyboard) and I have two problems:
When my
Activity
is displayed, myEditText
is focused but the keyboard is not displayed, I need to click again on it to show the keyboard (it should be displayed when myActivity
is displayed).And when I click done on the keyboard, the keyboard is dissmissed but the
EditText
stays focused and y don't want (because my edit is done).
To resume, my problem is to have something more like on the iPhone: which keep the keyboard sync with my EditText
state (focused / not focused) and of course does not present a soft-keyboard if there is a physical one.
Sometimes raukodraug's answer won't work. I've make it in this way with some trials and errors:
And the EditText part:
just add android:windowSoftInputMode="stateHidden" in manifest file...
For fragment, sure its working:
I combined everything here and for me it works:
Believe or not my problem with Soft Keyboard was resolved when I discovered that the Activities animations can disable the Soft Keyboard. When you call the intent with the
and
It can hide the Soft Keyboard and there isn't a way to show it.
All solutions given above (InputMethodManager interaction in OnFocusChangeListener.onFocusChange listener attached to your EditText works fine if you have single edit in the activity.
In my case I have two edits.
I have observed that onFocusChange is triggered for tvX with hasFocus=true (keyboard shown) but then for tvY with hasFocus=true (keyboard hidden). In the end, no keyboard was visible.
General solution should have correct statement in if "show keyboard if EditText text has focus"