Open pop up/external site link in current webview

二次信任 提交于 2019-12-01 07:36:30

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!