@@ -150,6 +150,7 @@ public class SearchView extends FrameLayout implements CoordinatorLayout.Attache
150150 private final SearchViewAnimationHelper searchViewAnimationHelper ;
151151 @ NonNull private final MaterialBackOrchestrator backOrchestrator =
152152 new MaterialBackOrchestrator (this );
153+ private final boolean backHandlingEnabled ;
153154 private final ElevationOverlayProvider elevationOverlayProvider ;
154155 private final Set <TransitionListener > transitionListeners = new LinkedHashSet <>();
155156
@@ -193,6 +194,7 @@ public SearchView(@NonNull Context context, @Nullable AttributeSet attrs, int de
193194 animatedMenuItems = a .getBoolean (R .styleable .SearchView_animateMenuItems , true );
194195 boolean hideNavigationIcon = a .getBoolean (R .styleable .SearchView_hideNavigationIcon , false );
195196 autoShowKeyboard = a .getBoolean (R .styleable .SearchView_autoShowKeyboard , true );
197+ backHandlingEnabled = a .getBoolean (R .styleable .SearchView_backHandlingEnabled , true );
196198
197199 a .recycle ();
198200
@@ -781,8 +783,9 @@ void setTransitionState(@NonNull TransitionState state) {
781783 listener .onStateChanged (this , previousState , state );
782784 }
783785
784- // Only automatically handle back if we have a search bar to collapse to.
785- if (searchBar != null ) {
786+ // Only automatically handle back if we have a search bar to collapse to, and if back handling
787+ // is enabled for the SearchView.
788+ if (searchBar != null && backHandlingEnabled ) {
786789 if (state .equals (TransitionState .SHOWN )) {
787790 backOrchestrator .startListeningForBackCallbacks ();
788791 } else if (state .equals (TransitionState .HIDDEN )) {
0 commit comments