I am coding an app which uses a webview to display HTML files. When the user clicks search this code is ran:
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) && ((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;
}
});
}
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.
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.
Thank you to all replies
Edit
For users in the future, this bug is only present in the following Android version:
Platform Version API Level VERSION_CODE
Android 4.0.3, 4.0.4 15 ICE_CREAM_SANDWICH_MR1