Commit fb26da6
[Menu][A11y] Fix context menu keyboard controls in Menu demo
Previously, pressing Enter on the context menu TextView in the menu demo would incorrectly open the menu. Additionally, pressing Ctrl+Enter would open the menu as a dialog, inconsistent with the floating menu style seen on long-press.
This change updates the OnKeyListener to:
Ignore Enter/DPAD_CENTER/Space key presses unless Ctrl is also held down.
When Ctrl+Enter is detected on API 24+, use showContextMenu(x, y) to display the menu as a floating menu centered on the view. This aligns its appearance with the long-press behavior.
On API < 24, fall back to showContextMenu(), which displays the menu as a dialog.
PiperOrigin-RevId: 8061982041 parent 98a73a6 commit fb26da6
File tree
1 file changed
+19
-4
lines changed1 file changed
+19
-4
lines changedLines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
111 | 126 | | |
112 | 127 | | |
113 | 128 | | |
| |||
0 commit comments