gpt4 book ai didi

javascript - android如何像GMail一样在webview中显示PopupMenu

转载 作者:太空狗 更新时间:2023-10-29 16:46:10 26 4
gpt4 key购买 nike

我想在我的应用程序(如 GMail)上的 webview 中显示 PopupMenu。

enter image description here

这是我的代码:

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
}

最佳答案

使用 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) {

}


}

关于javascript - android如何像GMail一样在webview中显示PopupMenu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27119026/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com