2012-02-10 157 views
0

我創建了一個web視圖,並試圖剛剛啓動google.com。 一切都編譯正確,但是當它打開時顯示默認網頁,顯示「網頁不可用」網頁http://www.google.com可能會暫時關閉,或者它可能已永久移動到新的網址。webview瀏覽器不加載

我錯過了什麼來打開網頁?我在統計員和我的手機上進行了測試。兩者都有網絡接入,我可以通過手機上的瀏覽器打開Goog​​le。

下面是我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 

     } 
    }); 
} 
} 

清單

<?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中

<?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> 

回答

1

您需要互聯網權限在你的男人ifest文件。

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