【问题标题】:android how to show PopupMenu in webview like GMailandroid如何在像GMail这样的webview中显示PopupMenu
【发布时间】:2015-01-23 00:04:00
【问题描述】:

我想在我的应用程序(如 GMail)的 web 视图中显示 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
}

【问题讨论】:

  • 有人需要回答吗?

标签: javascript android html webview popupmenu


【解决方案1】:

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

    }


}

【讨论】:

  • 他们是如何创建附件视图的,我的意思是他们使用的是自定义 html 布局?
猜你喜欢
  • 2013-01-12
  • 2020-12-16
  • 1970-01-01
  • 2012-05-28
  • 1970-01-01
  • 1970-01-01
  • 2012-09-03
  • 1970-01-01
  • 2012-03-29
相关资源
最近更新 更多