[Android] When a user taps off of an input control the keyboard no longer closes
See original GitHub issueDescription
Copied from https://github.com/dotnet/maui/issues/6933#issuecomment-1236381789
In XF when you click/tapped outside of a focused entry the entry would lose focus and the keyboard would close. This behavior wasn’t copied over to MAUI because the implementation on XF was very wrong and broke accessibility.
If we decide to “fix” this for MAUI .NET 7 we should not implement the “Unfocus” behavior and only make it so that it closes the keyboard.
Reasons to fix
- this is how it works in Forms
- we already have code for iOS that’s custom that does this so it’s compelling to do this in
Formsso we can match behavior for users migrating. - we can make it work in a way that doesn’t break accessibility like it did in XF
- We can make the behavior match
Formsin NET7 and then provide an API in NET8 that lets users toggle this behavior on/off foriOSandAndroid - Users currently don’t have an easy way to enable this behavior so as to match with
XF. At a later point we might have enough API surface for users to do this themselves easily but currently they do not.
Reasons not to fix for .NET 7
- This is not a standard feature of the platform and anytime we modify the platform behavior that will typically have consequences that we aren’t even aware of.
- We can leave the behavior how this is for now in NET7 and provide an API in NET8 that lets users toggle this behavior on/off for
iOSandAndroid - By default on iOS/Android if an input field has focus and then you click on a button the keyboard will not close. This is the desired behavior in a lot of scenarios (think chat app). If we add this behavior back into .NET 7 this will change the current behavior on Android so it might be better to wait until we can implement https://github.com/dotnet/maui/issues/12003
Concerns
The way this behavior worked in XF was to make the entire page clickable which made apps completely inaccessible. Anybody wanting to pass WCAG certification with an XF app were forced to write custom code to disable this behavior. The only place where I’ve seen this behavior is if the area you click off to is interactable in some format. For example, the maps app if you click off to the results but if you test with the WIFI app or contacts app they don’t work like this. If you want to add this behavior yourself I think this would be the best way to go about it https://stackoverflow.com/a/28939113 so you don’t confuse TalkBack.
I think we need to flesh out the use cases here a bit more so we can provide guidance or additional APIs to give people the ability to make these choices if they want to but we’re not going to make this the default behavior unless provided some examples that are accessible and preferable over the default Android behavior or if it can demonstrated that .NET MAUI breaks Android platform defaults.
Steps to Reproduce
- click on an entry
- click off the entry
- keyboard is still open
Link to public reproduction project repository
N/A
Version with bug
6.0 Release Candidate 2 or older
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android
Did you find any workaround?
- the workaround here would probably be to provide a func to
PageHandler.CreatePlatformViewand return your ownContentViewGroup. Then inside theContentViewGroupoverrideDispatchTouchand from there close the keyboard - https://github.com/PureWeen/ShanedlerSamples/tree/main/ShanedlerSamples/Library
Relevant log output
No response
Issue Analytics
- State:
- Created 9 months ago
- Reactions:5
- Comments:18 (6 by maintainers)

Top Related StackOverflow Question
I make one solution based on this one but without keyboard flicker everytime you repress it
The explanation is simple, if focused it will set the touch listener on receiving the touch it changed the flag KeepFocus to true
If KeepFocus is not set, the dispatch touch will unfocus If Unfocus the keyboard hides
There is still an issue which is if you touch another entry, it will still flicker but every other instance it working fine, might need to tune somthing to make it work at 100%
Hope I could be of some use
I’ve put together a behavior here that seems to work alright and cover most cases. T
https://github.com/PureWeen/ShanedlerSamples/tree/main/ShanedlerSamples/Library
Some version of this will probably make it into the keyboard