android – WebView需要WebViewClient才能正常工作吗?

我正在通过 android教程,并尝试了WebView的例子.这就是我最终的结论:

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吗?
(找不到任何文件)

编辑:

我注意到,当我在具有Google Api的模拟器中安装apk时,会出现此问题.在正常的模拟器(没有Google Api)上,它的行为与预期的一样.

解决方法

是的,您必须设置一个WebViewClient,该方法在覆盖的方法“shouldOverrideUrlLoading”上返回true,以便您的Webview加载您的应用程序中的URL.

让我知道,如果你想要一个例子.

编辑

@Aki WebViewClient.shouldOverrideUrlLoading Documentation

Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView. If WebViewClient is not provided,by default WebView will ask Activity Manager to choose the proper handler for the url. If WebViewClient is provided,return true means the host application handles the url,while return false means the current WebView handles the url.

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...