页面未显示在我的应用程序视图中

时间:2018-08-02 16:57:22

标签: android android-webview

我想在我的Web视图中加载我的Facebook页面,但是显示错误 当我通过色度加载它时,它会显示出来。这是我的代码;

var  mywebview: WebView =  findViewById<WebView>(R.id.webView1)
var webSettings: WebSettings = mywebview.getSettings()
mywebview.setWebViewClient( WebViewClient())
webSettings.setJavaScriptEnabled(true)
webSettings.userAgentString
//  myWebView.setWebViewClient( WebViewClient())
mywebview.loadUrl("http://www.facebook.com/769268423274829/feed") 

错误消息,但删除了mywebview.setWebViewClient(WebViewClient()) 让它通过Chromo打开而没有错误

enter image description here

2 个答案:

答案 0 :(得分:1)

use this line of  code


  <uses-permission android:name="android.permission.INTERNET">
    </uses-permission>



 WebView webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.google.com");

答案 1 :(得分:0)

由于Facebook链接有效(对我来说适用于Google Chrome),并且您已设置了访问互联网的权限,因此请在WebView上附加一个侦听器,然后查看其输出内容。

var mywebview: WebView =  findViewById<WebView>(R.id.webView1)
var webSettings: WebSettings = mywebview.getSettings()
mywebview.setWebViewClient(object : WebViewClient() {
    override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) {
            Log.e("CLASS NAME", errorCode.toString())
            super.onReceivedError(view, errorCode, description, failingUrl)
        }
    })
webSettings.setJavaScriptEnabled(true)
webSettings.userAgentString
mywebview.loadUrl("http://www.facebook.com/769268423274829/feed")

Here is some more information (and a nice example with error handling and progress meter) on WebViews.