【问题标题】:WebView is not opening google.comWebView 未打开 google.com
【发布时间】:2015-02-12 17:46:10
【问题描述】:

我的 webview 能够同时加载 https 和 http 网站 但不是https://www.google.com

它也不会抛出任何错误。

这是我的代码。我无法解决这个问题

     super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Button btn = (Button) findViewById(R.id.Button1);
        final EditText et=(EditText)findViewById(R.id.EditText1);
        final WebView wv1=(WebView)findViewById(R.id.WebView1);

        wv1.getSettings().setJavaScriptEnabled(true);
        wv1.getSettings().setDomStorageEnabled(true);
        wv1.setInitialScale(100);

        et.setFocusable(true);


        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                 wv1.loadUrl(et.getText().toString());  
            }
        });

        wv1.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return true;
            }
ca
            public void onPageFinished(WebView view, String url) {
                Toast.makeText(getApplicationContext(),"Page Finished",Toast.LENGTH_LONG).show();
            }

            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                Toast.makeText(getApplicationContext(),"Error",Toast.LENGTH_LONG).show();
            }
        });

        wv1.loadUrl("https://www.bing.com");

感谢您的任何帮助。

【问题讨论】:

标签: android webview


【解决方案1】:

您的代码中存在错误

您的代码

public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return true;
        }

正确代码

 public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }

ShouldOverrideUrlLoading 应该return false在 web 视图中打开 urlTrue 用于在其他应用中打开。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-19
    • 2011-05-24
    • 1970-01-01
    • 2017-07-08
    • 1970-01-01
    • 2017-03-29
    • 1970-01-01
    • 2021-07-13
    相关资源
    最近更新 更多