[英]WebView page not available - Android
I have a basic WebView
application that should display www.google.com. 我有一个基本的
WebView
应用程序,应显示www.google.com。 Though the website can be accessed through the in-built browser, I am not able to do so from the WebView
. 尽管可以通过内置浏览器访问该网站,但我无法从
WebView
。 I have gone through a large number of questions on various forums and incorporated all suggestions, but nothing seems to have worked. 我在各个论坛上讨论了很多问题,并纳入了所有建议,但似乎没有任何效果。 I have ensured:
我保证:
1. The uses-permission
tag for allowing internet access is a child of the manifest
tag. 1.允许访问互联网的
uses-permission
标签是manifest
标签的子类。
2. Enabled javascript for the WebView. 2.为WebView启用了javascript。
The manifest file: 清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sriram.hellowebview"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".helloWebview"
android:label="@string/title_activity_hello_webview" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Layout: 布局:
<?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/helloWebview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
Code: 码:
/* Program to create sample webview.
* Steps:
* 1. Create webview.
* 2. Show some website in it.
* 3. Show some transitions as well.
*/
package com.sriram.hellowebview;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.webkit.WebView;
public class helloWebview extends Activity {
WebView myWebview;
String url = "www.google.com";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_webview);
Log.v(this.toString(), "Starting activity.");
myWebview = (WebView) findViewById(R.id.helloWebview);
Log.v(this.toString(), "Getting settings.");
myWebview.getSettings().setJavaScriptEnabled(true);
Log.v(this.toString(), "Loading URL now.");
myWebview.loadUrl(url);
Log.v(this.toString(), "Loaded URL.");
//open all links within the same webview.
//myWebview.setWebViewClient(new WebViewClient());
//Log.v(this.toString(), "All done here.");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_hello_webview, menu);
return true;
}
}
String url = "https://www.google.co.in/";
要不然
super.loadUrl("https://www.google.co.in//");
尝试在链接前面添加http://
WebView wt;
wt.loadUrl("http://www.google.com/");
and sometimes in android 4.0 it will be blank, use android:hardwareAccelerated="true"
in manifest file. 有时在android 4.0中为空白,请在清单文件中使用
android:hardwareAccelerated="true"
。
You need to add http:// in the url string...the url must look like this 您需要在网址字符串中添加http:// ...网址必须看起来像这样
String url = " http://www.google.com/ "; 字符串url =“ http://www.google.com/ ”;
now do 现在做
webview.loadurl(url); webview.loadurl(url);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.