2014-11-25 47 views
5

我想表明的PopupMenu中的WebView我的應用程序如Gmail。機器人如何在網頁視圖顯示的PopupMenu例如Gmail

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 
} 
+0

有誰需要回答? – nAkhmedov 2015-03-26 10:14:57

回答

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

    } 


} 
+0

他們如何創造attachement的觀點,我的意思是他們使用的自定義HTML佈局? – nAkhmedov 2015-05-18 05:22:52