Skip to content

Commit 97d957c

Browse files
committed
[SearchBar] Fix a11y issue where SearchBar darkens when focused with TalkBack
PiperOrigin-RevId: 679614664
1 parent 246fa67 commit 97d957c

File tree

2 files changed

+4
-38
lines changed

2 files changed

+4
-38
lines changed

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
import android.view.Menu;
4545
import android.view.View;
4646
import android.view.ViewGroup;
47-
import android.view.accessibility.AccessibilityManager;
48-
import android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener;
4947
import android.view.accessibility.AccessibilityNodeInfo;
5048
import android.widget.EditText;
5149
import android.widget.ImageButton;
@@ -148,10 +146,6 @@ public class SearchBar extends Toolbar {
148146
private boolean defaultScrollFlagsEnabled;
149147
private MaterialShapeDrawable backgroundShape;
150148

151-
@Nullable private final AccessibilityManager accessibilityManager;
152-
private final TouchExplorationStateChangeListener touchExplorationStateChangeListener =
153-
(boolean enabled) -> setFocusableInTouchMode(enabled);
154-
155149
public SearchBar(@NonNull Context context) {
156150
this(context, null);
157151
}
@@ -209,35 +203,6 @@ public SearchBar(@NonNull Context context, @Nullable AttributeSet attrs, int def
209203
ViewCompat.setElevation(this, elevation);
210204
initTextView(textAppearanceResId, text, hint);
211205
initBackground(shapeAppearanceModel, backgroundColor, elevation, strokeWidth, strokeColor);
212-
213-
accessibilityManager =
214-
(AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
215-
setupTouchExplorationStateChangeListener();
216-
}
217-
218-
private void setupTouchExplorationStateChangeListener() {
219-
if (accessibilityManager != null) {
220-
// Handle the case where touch exploration is already enabled.
221-
if (accessibilityManager.isEnabled() && accessibilityManager.isTouchExplorationEnabled()) {
222-
setFocusableInTouchMode(true);
223-
}
224-
225-
// Handle the case where touch exploration state can change while the view is active.
226-
addOnAttachStateChangeListener(
227-
new OnAttachStateChangeListener() {
228-
@Override
229-
public void onViewAttachedToWindow(View ignored) {
230-
accessibilityManager.addTouchExplorationStateChangeListener(
231-
touchExplorationStateChangeListener);
232-
}
233-
234-
@Override
235-
public void onViewDetachedFromWindow(View ignored) {
236-
accessibilityManager.removeTouchExplorationStateChangeListener(
237-
touchExplorationStateChangeListener);
238-
}
239-
});
240-
}
241206
}
242207

243208
private void validateAttributes(@Nullable AttributeSet attributeSet) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,10 @@ private void setTransitionState(
821821
}
822822

823823
updateListeningForBackCallbacks(state);
824+
825+
if (searchBar != null && state == TransitionState.HIDDEN) {
826+
searchBar.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
827+
}
824828
}
825829

826830
private void updateModalForAccessibility(@NonNull TransitionState state) {
@@ -932,9 +936,6 @@ public void clearFocusAndHideKeyboard() {
932936
editText.post(
933937
() -> {
934938
editText.clearFocus();
935-
if (searchBar != null) {
936-
searchBar.requestFocus();
937-
}
938939
ViewUtils.hideKeyboard(editText, useWindowInsetsController);
939940
});
940941
}

0 commit comments

Comments
 (0)