我想在我的应用上像GMail一样在webview中显示PopupMenu。
这是我的代码:
webView.addJavascriptInterface(new WebAppInterface(getActivity()), "ScriptToAndroid");
<div class="moreover_icon" onclick="showPopup('file_attach_path', event)">
<img class="overflow_icon" src="android_moreover_icon"/>
</div>
<script type="text/javascript">
function showPopup(file_path, event) {
ScriptToAndroid.showPopupDialog(file_path, pos_x, pos_y);
}
</script>
@JavascriptInterface
public void showPopupDialog(String filePath, int x, int y) {
//show PopupMenu
}
答案 0 :(得分:0)
使用WebViewClient
mWebView = (WebView) findViewById(R.id.webView);
mWebView.setWebViewClient(new WebClient(this));
拦截shouldOverrideUrlLoading()
public class WebClient extends WebViewClient {
MainActivity mainActivity;
public WebClient(MainActivity activity) {
mainActivity = activity;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("xxx")) {
Log.i("show pop", "xx");
}
return false;
}
@Override
public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) {
return super.shouldOverrideKeyEvent(view, event);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
}
}