我正在浏览android教程,并尝试使用WebView
示例。这是我结束了:WebView是否需要WebViewClient才能工作?
WebAppActivity
public class WebAppActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wv = (WebView) findViewById(R.id.webView1);
wv.loadUrl("http://www.google.com");
}
}
的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/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</WebView>
</LinearLayout>
而是尽快在应用程序本身加载页面,作为应用程序启动默认的Android浏览器打开,并在浏览器中加载页面而不是应用程序。当我按回时,我会返回到显示空白屏幕的应用程序活动。
有谁知道为什么会发生这种情况?
编辑:
清单
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".WebAppActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
这只是表明我已经添加INTERNET权限
编辑:
只要我在应用程序中添加WebViewClient
,
wv.setWebViewClient(new WebViewClient() {});
页面加载。这是预期的行为? Android WebView 是否需要一个WebViewClient? (找不到它的任何文件)
编辑:
我注意到,当我在有谷歌API的仿真器安装APK出现此问题。在普通模拟器上(没有Google API),它的行为如预期。
你的问题已经得到解答:http://stackoverflow.com/questions/2378800/android-webview-click-opens-default-browser – ariefbayu 2012-01-05 09:43:39
@silent请仔细阅读。这不是我的问题。我无法加载第一页本身,它加载在浏览器中而不是应用程序中。请参阅Flo的评论 – 2012-01-05 09:48:27
不,我不认为他在讨论点击链接的网页本身。这听起来像网页永远不会加载在WebView中。 – Flo 2012-01-05 09:49:33