Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - Implement findOnPage into a WebView
    text
    copied!<p>I am coding an app which uses a webview to display HTML files. When the user clicks search this code is ran:</p> <pre><code>public void search() { container = (LinearLayout)findViewById(R.id.layoutId); nextButton = new Button(this); nextButton.setText("Next"); nextButton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ mWebView.findNext(true); } }); container.addView(nextButton); closeButton = new Button(this); closeButton.setText("Close"); closeButton.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ container.removeAllViews(); } }); container.addView(closeButton); findBox = new EditText(this); findBox.setMinEms(30); findBox.setSingleLine(true); findBox.setHint("Search"); findBox.setOnKeyListener(new OnKeyListener(){ @Override public boolean onKey(View v, int keyCode, KeyEvent event){ if((event.getAction() == KeyEvent.ACTION_DOWN) &amp;&amp; ((keyCode == KeyEvent.KEYCODE_ENTER))){ mWebView.findAll(findBox.getText().toString()); try{ Method m = WebView.class.getMethod("setFindIsUp", Boolean.TYPE); m.invoke(mWebView, true); }catch(Exception ignored){} } return false; } }); } </code></pre> <p>The code I'm using runs fine generally, with some bugs in Android 4.0. I would like a solution as presented in the Android Browser, where the top bar becomes the search area.</p> <p>When I have tried to implement this I have failed. Is there a way to properly implement this into a webview for an Android application? I would like a more elegant and functional design than what I currently use.</p> <p>Thank you to all replies</p> <p><em>Edit</em></p> <p>For users in the future, this bug is only present in the following Android version:</p> <pre><code>Platform Version API Level VERSION_CODE Android 4.0.3, 4.0.4 15 ICE_CREAM_SANDWICH_MR1 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload