2014-05-02 25 views
0

我在我的活動中打開了一些網頁,當我點擊我的應用程序鏈接時,它會打開本身的鏈接。但是當頁面加載時,如果我點擊網頁中的某個鏈接,它會在系統的默認瀏覽器中打開。我如何防止它?在活動中嵌入網頁在點擊第二個鏈接後

例如:

這是我的代碼部分onCreate()

WebView myWebView = (WebView) findViewById(R.id.webview); 
    WebSettings webSettings = myWebView.getSettings(); 
    webSettings.setJavaScriptEnabled(true); 
    myWebView.loadUrl("http://"+URL); 

回答

0

您應該添加一個WebViewClient到您的WebView,然後覆蓋shouldOverrideUrlLoading方法如下。

myWebView.setWebViewClient(new WebViewClient(){ 
    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 
     // do what you want 

     // return true if the host application wants to leave the current 
     // WebView and handle the url itself, otherwise return false. 
     return true; 
    } 
}); 
相關問題