maui: Soft Keyboard does not Pop Up when Entry View's Focus is set to True Programmatically
Description
When Focus is set to an Entry view programmatically (entryTest.Focus()), the cursor blinks in the edit field of the Entry view, but the soft keyboard does not pop up as it should until you physically touch the Entry view. In comparison to Xamarin Forms where the keyboard pops up when executing entryTest.Focus().
Also, entryTest.Focus() is ignored when placed in the OnAppearing Event.
Video demo of Maui App:
Video demo of Xamarin Forms version:
XAML:

Code Behind:

Steps to Reproduce
- Create a new blank Maui app
- Add and Entry View and name it entryTest
- Add 2 Buttons and set Text to “Set Focus” and “Set Unfocus”
- In the Code behind for the 1st button add code entryTest.Focus()
- In the Code behind for the 2nd button add code enryTest.Unfocus()
- Run the App
- Click the Set Focus button.
- Notice the Entry field cursor blinks
- Notice the keyboard does not pop up
- Tap the Entry field.
- Notice the keyboard pops up.
Version with bug
Preview 14 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 11
Did you find any workaround?
Workaround
I added a mapper here that you can copy to add this behavior for android.
One thing to note is that if your intention is to open the keyboard you should use
KeyboardManager.ShowKeyboard not Focus
Using Focus to influence the Keyboard has always felt like a hack to me in general.
Relevant log output
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 16
- Comments: 26 (3 by maintainers)
Commits related to this issue
- Show keyboard on Android entry/editor/searchbar focus (#12890) ### Description of Change Show keyboard on Android entry/editor/searchbar focus ### Issues Fixed <!-- Please make sure that the... — committed to dotnet/maui by PureWeen a year ago
- Show keyboard on Android entry/editor/searchbar focus (#12890) Show keyboard on Android entry/editor/searchbar focus <!-- Please make sure that there is a bug logged for the issue being fixed. The b... — committed to dotnet/maui by PureWeen a year ago
to this day it still doesn’t work
Surprised to see ! It isn’t working till today.
I added a mapper here that you can copy to add this behavior for android.
One thing to note is that if your intention is to open the keyboard you should use KeyboardManager.ShowKeyboard not
FocusUsing
Focusto influence theKeyboardhas always felt like a hack to me in general.Quick Solution : Make Entry , Editor or Any thirdparty controls IsEnabled = false then Entry.UnFocus() to hide the key board and Again don’t forget to make IsEnabled property to true as soon as the task is completed. 😃
This definitely needs a fix
Here’s some code you can use to interact with the keyboard for the time being
https://github.com/PureWeen/ShanedlerSamples/tree/main/ShanedlerSamples/Keyboard
If you call “ShowKeyboard” there’s no need to call “Focus” when using this code.
I’ve encountered a different problem. Keyboard is not hiding when unfocus entry. I made a wordaround in handler:
I use own observable method, but you can use events.
I’ve encountered the same problem. But when I use “Entry” inside Grid instead of StackLayout, it works just fine. Entry and StackLayout don’t get along yet.