在辅助屏幕上克隆/复制webview

时间:2018-02-07 10:05:21

标签: android android-webview

我的MainActivity上有一个webview ..它加载了一个由onclick按钮处理设置的url。 当webview加载某个网页时。 我想克隆或复制(甚至移动)它到我的辅助显示器/屏幕。

对于辅助显示器,我有一个单独的Presentation类:

True

然而这不起作用,它甚至可能吗?我走错了路吗?在互联网上找不到关于二级屏幕处理的内容。

更新 我不想加载相同的页面,需要在MainActivity上加载当前页面:想要登录MainActivity然后在登录后重复/将其移动到第二个屏幕(readonly)。

1 个答案:

答案 0 :(得分:0)

As per Android dev page :
Handling Page Navigation
When the user clicks a link from a web page in your WebView, the default behavior is for Android to launch an application that handles URLs. Usually, the default web browser opens and loads the destination URL. However, you can override this behavior for your WebView, so links open within your WebView. You can then allow the user to navigate backward and forward through their web page history that's maintained by your WebView.

To open links clicked by the user, simply provide a WebViewClient for your WebView, using setWebViewClient(). For example:

WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
That's it. Now all links the user clicks load in your WebView.

If you want more control over where a clicked link load, create your own WebViewClient that overrides the shouldOverrideUrlLoading() method. For example:

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals("www.example.com")) {
            // This is my web site, so do not override; let my WebView load the page
            return false;
        }
        // Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }
}
Then create an instance of this new WebViewClient for the WebView:


  [1]: https://developer.android.com/guide/webapps/webview.html
相关问题