Skip to content

Commit f307771

Browse files
imhappidrchen
authored andcommitted
[SearchView] Make SearchView root unfocusable
PiperOrigin-RevId: 833520163
1 parent 176e92d commit f307771

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/java/com/google/android/material/search/SearchView.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,12 @@ public Toolbar getToolbar() {
749749
return toolbar;
750750
}
751751

752+
/** Returns the container view containing the non-scrim content of the {@link SearchView}. */
753+
@NonNull
754+
public View getSearchContainer() {
755+
return rootView;
756+
}
757+
752758
/** Returns the main {@link EditText} which can be used for hint and search text. */
753759
@NonNull
754760
public EditText getEditText() {
@@ -959,6 +965,17 @@ private void updateNavigationIconProgressIfNeeded() {
959965
void requestFocusAndShowKeyboardIfNeeded() {
960966
if (autoShowKeyboard) {
961967
requestFocusAndShowKeyboard();
968+
} else if (!isInTouchMode()) {
969+
// We still want to request focus if we are in non-touch mode so that focus doesn't go
970+
// behind the searchview.
971+
editText.postDelayed(
972+
() -> {
973+
if (editText.requestFocus()) {
974+
// Workaround for talkback issue when clear button is clicked
975+
editText.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
976+
}
977+
},
978+
TALKBACK_FOCUS_CHANGE_DELAY_MS);
962979
}
963980
}
964981

lib/java/com/google/android/material/search/res/layout/mtrl_search_view.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
android:id="@+id/open_search_view_root"
3030
android:layout_width="match_parent"
3131
android:layout_height="match_parent"
32-
android:focusable="true"
33-
android:focusableInTouchMode="true"
3432
android:touchscreenBlocksFocus="true"
3533
android:keyboardNavigationCluster="true"
3634
android:visibility="gone">

0 commit comments

Comments
 (0)