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.
Inside your manifest:
android:windowSoftInputMode="stateAlwaysVisible"
- initially launched keyboard.android:windowSoftInputMode="stateAlwaysHidden"
- initially hidden keyboard.I like to use also
"adjustPan"
because when the keyboard launches then the screen auto adjusts.I had the same problem. Immediately after editText VISIBILITY change from GONE to VISIBLE, I had to set the focus and display the soft keyboard. I achieved this using the following code:
It works for me with 100ms delay, but failed without any delay or with only a delay of 1ms.
Commented part of code shows another approach, which works only on some devices. I tested on OS versions 2.2 (emulator), 2.2.1 (real device) and 1.6 (emulator).
This approach saved me a lot of pain.
I discovered a strange behaviour, since in one of my apps, the soft keyboard was automatically showing on entering the activity (there is an editText.requestFocus() in onCreate).
On digging further, I discovered that this was because there is a ScrollView around the layout. If I remove the ScrollView, the behaviour is as described in the original problem statement: only on clicking the already focused editText does the soft keyboard show up.
If it doesn't work for you, try putting in a ScrollView -- it's harmless anyway.
Using Xamarin, this works for me inside a Fragment:
I am agree with raukodraug therefor using in a swithview you must request/clear focus like this :
Regards.
To force the soft keyboard to appear, you can use
And for removing the focus on
EditText
, sadly you need to have a dummyView
to grab focus.I hope this helps
To close it you can use
This works for using it in a dialog