我想使用searchView
在webview
中进行搜索,当我在其中搜索时,webview已更改并放大了heppeninig,我使用webView显示其中的epub书我展示了更多细节两个截图(之后,之前)并在此粘贴我的代码
我的Android设备操作系统是Android Kitkat
代码中的更多细节:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_activity_reader, menu);
this.menu = menu;
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (!query.isEmpty()) {
searchEnabled = true;
if (!flag) {
webView.findAllAsync(query);
flag = true;
try {
Method m = WebView.class.getMethod("setFindIsUp", Boolean.TYPE);
m.invoke(webView, true);
} catch (Throwable ignored) {
}
} else {
webView.findNext(true);
}
Log.i("webview", webView.getScrollY() + "");
}
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (newText.isEmpty()) {
try {
Method m = WebView.class.getMethod("setFindIsUp", Boolean.TYPE);
m.invoke(webView, false);
} catch (Throwable ignored) {
}
}
flag = false;
return true;
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
try {
Method m = WebView.class.getMethod("setFindIsUp", Boolean.TYPE);
m.invoke(webView, false);
} catch (Throwable ignored) {
}
return false;
}
});
return true;
}
答案 0 :(得分:0)
尝试禁用webview的自动缩放功能:
webview.getSettings().setBuiltInZoomControls(false);
webview.getSettings().setSupportZoom(false);