Open pop up/external site link in current webview

后端 未结 1 423
囚心锁ツ
囚心锁ツ 2021-01-14 00:41

I am currently writing a webview, it first loads a twitter page (say, NHL, http://twitter.com/nhl) as you can see, you can find the tweet for NHL, and each NHL tweet has ano

相关标签:
1条回答
  • 2021-01-14 01:43

    You can control this through the WebViewClient class. Simply extend it and override the default implementation to get the desired configuration then set it as the client for your current webview.

    Activity

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
                // set the webViewClient to a new instance of your custom WebViewClient
    
        webview.setWebViewClient(new WebActivityClient( this ));
    
    }
    

    Custom Client

    /** WebViewClient class for WebView in WebActivity */
    private class WebActivityClient extends WebViewClient {
    
        public static final String TAG = "WebActivityClient";
        private Context context;
    
        /** Constructor used to grab the context */
        public WebActivityClient( Context context ) {
            this.context = context;
        }
    
        /** Override to load every link within the page inside this webview instead of using
         * android's default application
         * #7 http://developer.android.com/resources/tutorials/views/hello-webview.html */
        @Override
        public boolean shouldOverrideUrlLoading( WebView view, String url ) {
            view.loadUrl(url);
            return true;
        }
    
    }
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题