diff --git a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.android.cs b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.android.cs index b29bb03d67..680db32cc9 100644 --- a/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.android.cs +++ b/src/CommunityToolkit.Maui/Behaviors/PlatformBehaviors/Touch/TouchBehavior.android.cs @@ -44,6 +44,7 @@ protected override void OnAttachedTo(VisualElement bindable, AView platformView) viewGroup = platformView.GetParentOfType(); platformView.Touch += OnTouch; + platformView.KeyPress += OnKeyPressed; UpdateClickHandler(); accessibilityManager = platformView.Context?.GetSystemService(Context.AccessibilityService) as AccessibilityManager; @@ -89,6 +90,7 @@ protected override void OnDetachedFrom(VisualElement bindable, AView platformVie { view.Touch -= OnTouch; view.Click -= OnClick; + view.KeyPress -= OnKeyPressed; } Element = null; @@ -117,6 +119,15 @@ void UpdateClickHandler() } } + void OnKeyPressed(object? sender, AView.KeyEventArgs e) + { + if (e.KeyCode == Keycode.Space && e.Event?.Action == KeyEventActions.Up) + { + IsCanceled = false; + HandleTouchEnded(TouchStatus.Completed); + } + } + void OnClick(object? sender, EventArgs args) { if (!IsEnabled)