diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewRenderer.cs index 9269bd273c45..b5cae650f984 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewRenderer.cs @@ -84,8 +84,8 @@ protected override void OnAttachedToWindow() protected override void OnDetachedFromWindow() { base.OnDetachedFromWindow(); - _isAttached = false; + _adapter.CloseContextActions(); _adapter.IsAttachedToWindow = _isAttached; } diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ActionModeMenuShouldNotBeVisibleAfterSwitchingTab.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ActionModeMenuShouldNotBeVisibleAfterSwitchingTab.png new file mode 100644 index 000000000000..a2239fd83d4a Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ActionModeMenuShouldNotBeVisibleAfterSwitchingTab.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19831.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19831.cs new file mode 100644 index 000000000000..23d33d447628 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue19831.cs @@ -0,0 +1,31 @@ +#if ANDROID +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue19831 : _IssuesUITest +{ + public override string Issue => "[Android] Action mode menu doesn't disappear when switch on another tab"; + + public Issue19831(TestDevice device) + : base(device) + { } + + [Test] + public void ActionModeMenuShouldNotBeVisibleAfterSwitchingTab() + { + _ = App.WaitForElement("Item1"); + + // 1. Open a context menu. + App.LongPress("Item1"); + + // 2. Navigate to a different tab. + App.Click("button"); + + // 3. The test passes if the action mode menu is not visible. + VerifyScreenshot(); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases/Issues/Issue19831.xaml b/src/Controls/tests/TestCases/Issues/Issue19831.xaml new file mode 100644 index 000000000000..c52ccd1a9fa7 --- /dev/null +++ b/src/Controls/tests/TestCases/Issues/Issue19831.xaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + Item1 + Item2 + + + +