问题描述
我是eclipse / Java的新手。 我搜索了答案,但没有任何解决方案。 我希望有人可以指导我。 我正在尝试使用android应用程序启动网页,但是在Android虚拟仿真中却出现了空白页。
这是我的代码
package com.example.t4;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.google.com");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
这是AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.t4"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.t4.MainActivity"
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>
</manifest>
这是activity_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"
/>
</LinearLayout>
我不确定自己在做什么错。 该代码运行没有错误。 我只得到一个黑屏。 任何帮助深表感谢。 提前致谢。
1楼
尝试放置myWebView.getSettings().setJavaScriptEnabled(true);
//启用JavaScript
myWebView.loadUrl("http://www.google.com");
2楼
查看此 。 我使用像您一样的“ www.google.com”进行了测试,并提出了空白视图。 我使用了“ ”,它运行良好。 试试看你的吗? 但是也可以随意窃取示例代码。
3楼
重新启动您的应用程序(我的意思是再次单击“运行”),并确保您已如上所述启用JavaScript。