2014-11-25 18 views
5

Voglio mostrare PopupMenu in webview sulla mia app come GMail.android come mostrare PopupMenu in webview come GMail

enter image description here

Ecco il mio codice:

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

Qualcuno deve rispondere? – nAkhmedov

risposta

0

Utilizzare un WebViewClient

mWebView = (WebView) findViewById(R.id.webView); 
mWebView.setWebViewClient(new WebClient(this)); 

intercetta 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

Come hanno creato le viste degli allegati, voglio dire che stanno usando un layout html personalizzato? – nAkhmedov