title: How to search for text in a WebView Android?
body: <p>I have an app that uses WebViews (minSdkVersion 17). It would be very helpful if it was possible to add a search (and highlight found result(s)) function. The thing is that my programming skills are very low and the search for the Holy Grail returned no good answers.</p>
  
  <p>I found this topics (and some moe, including other forums):
  <a href="https://stackoverflow.com/questions/16849990/how-to-search-text-in-webview">how to search text in webview</a> ,
  <a href="https://stackoverflow.com/questions/11910041/android-highlight-text-in-webview-above-android-version-4-0-3">Android - Highlight text in WebView above android version 4.0.3</a> ,
  <a href="https://stackoverflow.com/questions/18293317/search-text-on-webview-android">search text on WebView android</a>
  and a few others, but all of the are either incomplete for me to understand how they work or the code found is too old and there are way to may errors to fix (due to changes in android studio, I guess) for me to make something useful from them.</p>
  
  <p>My XML from the activity:</p>
  
  <pre><code>    &lt;ScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_above="@id/footer"
      android:layout_below="@+id/layoutId"&gt;
  
      &lt;WebView
          android:id="@+id/webviewautoturisme"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;&lt;/WebView&gt;
  &lt;/ScrollView&gt;
  
  &lt;RelativeLayout
      android:id="@+id/layoutId"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:orientation="horizontal"&gt;
  
      &lt;Button
          android:id="@+id/nextButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentEnd="true"
          android:text="Caută"
          android:textColor="#ffffff"
          android:textStyle="bold" /&gt;
  
      &lt;EditText
          android:id="@+id/findBox"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_toStartOf="@+id/nextButton"
          android:hint="Caută după localitate"
          android:maxLines="1" /&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;RelativeLayout
      android:id="@+id/footer"
      android:layout_width="wrap_content"
      android:layout_height="95dp"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"&gt;
  
      &lt;Button
          android:id="@+id/buttoBACK"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/adView"
          android:layout_centerHorizontal="true"
          android:minWidth="150dp"
          android:text="@string/sBackMainMenu"
          android:textAllCaps="true"
          android:textColor="#FFFFFF"
          android:textStyle="bold" /&gt;
         &lt;/RelativeLayout&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Is is something that I found, made some small improvements to the code, since it was a bit outdated, and I wanted to use the java also, but I had no luck.
  I also found out that there is a SearchView, so in another activity I used:</p>
  
  <pre><code>&lt;SearchView
      android:id="@+id/searchField"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:queryHint="Căutare după localitate"
      android:orientation="horizontal"&gt;
  &lt;/SearchView&gt;
  </code></pre>
  
  <p>and the Java :</p>
  
  <pre><code>package ro....;
  
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.net.ConnectivityManager;
  import android.net.NetworkInfo;
  import android.os.Bundle;
  import android.support.v7.app.AlertDialog;
  import android.support.v7.app.AppCompatActivity;
  import android.view.MotionEvent;
  import android.view.View;
  import android.webkit.WebView;
  
  import com.google.android.gms.ads.AdRequest;
  import com.google.android.gms.ads.AdView;
  import com.google.android.gms.ads.MobileAds;
  
  public class PKWinListActivity extends AppCompatActivity {
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_pkwinlist);
  
      MobileAds.initialize(getApplicationContext(), "ca-app-pub-....");
      AdView mAdView = (AdView) findViewById(R.id.adView);
      AdRequest adRequest = new AdRequest.Builder().addTestDevice("....").addTestDevice("....").addTestDevice("....").build();
      mAdView.loadAd(adRequest);
  
      findViewById(R.id.buttoBACK)
              .setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      finish();
                  }
  
              });
  
      if (isMobileDataEnabled()) {
  
          WebView myWebView = (WebView) findViewById(R.id.webviewautoturisme);
          myWebView.loadUrl("https://www...");
  
          myWebView.setOnTouchListener(new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  return true;
              }
          });
  
      } else {
          //Mobile data is disabled here
          new AlertDialog.Builder(this).setTitle(getString(R.string.sDataReqMes))
                  .setMessage(getString(R.string.sDataReqEnable)).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
              }
          }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
  
              @Override
              public void onClick(DialogInterface dialog, int which) {
                  finish();
              }
          }).show();
  
  
      }
  }
  
  
  private boolean isMobileDataEnabled() {
      ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo mobileDataEnabled = connectivityManager.getActiveNetworkInfo();
      return mobileDataEnabled != null &amp;&amp; mobileDataEnabled.isConnected();
  }
  
  }
  </code></pre>
  
  <p>The problem is that I can't figure out how to do the search button work, since the previous solutions I found are outdated.
  How to make the search button work?</p>