@@ -328,7 +328,7 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
328328 menu .findItem (R .id .action_share_image ).setVisible (true );
329329 menu .findItem (R .id .action_load_epub ).setVisible (isExperimentalFeaturesEnabled );
330330
331- // SearchView (View Mode)
331+ // Setup SearchView for view-mode
332332 setupSearchView ((SearchView ) menu .findItem (R .id .action_search_view ).getActionView ());
333333
334334 // Set various initial states
@@ -683,7 +683,7 @@ private void setupSearchView(SearchView searchView) {
683683 if (searchView == null ) {
684684 return ;
685685 }
686- // Only setup SearchView for view-mode, to avoid additional setup for edit-mode
686+ // Only setup SearchView for view-mode, to avoid unnecessary setup for edit-mode
687687 if (!_isPreviewVisible || _webView == null ) {
688688 return ;
689689 }
@@ -720,6 +720,17 @@ public boolean onQueryTextChange(String text) {
720720 return search (text );
721721 }
722722 });
723+ searchView .addOnAttachStateChangeListener (new View .OnAttachStateChangeListener () {
724+ @ Override
725+ public void onViewAttachedToWindow (@ NonNull View v ) {
726+ }
727+
728+ @ Override
729+ public void onViewDetachedFromWindow (@ NonNull View v ) {
730+ searchView .setQuery ("" , false ); // This will make onQueryTextChange be called back
731+ searchView .setIconified (true );
732+ }
733+ });
723734
724735 // Because SearchView doesn't provide a public API to add custom buttons
725736 // We must get the searchPlate (the layout containing the text field and close button) from SearchView
0 commit comments