简体   繁体   English

WebView浏览器未加载

[英]webview browser not loading

I created a web view and im trying to just launch google.com for now. 我创建了一个网络视图,并试图立即启动google.com。 Everything compiles right but when it opens it shows the default web page that says "Webpage not avaialable" The webpage at http://www.google.com might be temporarly down or it may have moved permantly to a new web address. 一切编译正确,但打开时会显示默认网页,显示“网页不可用” 。http://www.google.com上的网页可能暂时关闭或可能已永久移动到新的网址。

What am i missing to get this to open the web page? 我不知道该怎么打开网页? I tested it in the enumerator and on my phone. 我在枚举器和手机上对其进行了测试。 Both have web acess i can open google just fine from a browser on my phone. 两者都有网络访问权限,我可以从手机上的浏览器打开google。

Below is my webview.jave webview Manifest and Main.xml 下面是我的webview.jave webview清单和Main.xml

package com.webview;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;

public class WebViewActivity extends Activity { 

WebView mWebView; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    final Activity mActivity = this; 
    super.onCreate(savedInstanceState); 

    this.getWindow().requestFeature(Window.FEATURE_PROGRESS); 
    setContentView(R.layout.main); 

    // Makes Progress bar Visible 
    getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 

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

    mWebView.setWebChromeClient(new WebChromeClient()  
    { 
        public void onProgressChanged(WebView view, int progress)   
        { 
            //Make the bar disappear after URL is loaded, and changes string to Loading... 
            mActivity .setTitle("Loading..."); 
            mActivity .setProgress(progress * 100); //Make the bar disappear after URL is loaded 

        } 
    }); 
} 
} 

Manifest 表现

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.webview" 
android:versionCode="1" 
android:versionName="1.0"> 
<uses-sdk android:minSdkVersion="10" /> 

<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".WebViewActivity" 
        android:label="@string/app_name"> 
    <intent-filter> 
        <action android:name="android.intent.action.MAIN" /> 
        <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
</activity> 

</application> 

Main.xml Main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
android:layout_width="fill_parent"  
android:layout_height="fill_parent"  
android:orientation="vertical">  

<WebView   
    android:id="@+id/webview"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
/>  

<TextView  
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello"
/>
</LinearLayout>

您的清单文件中需要Internet许可。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM