21

如何在 webView中打开此链接。这是在浏览器上运行,但它不在 webView android 中运行。请给出解决方案。

4

3 回答 3

41

活动:

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class WebViewActivity extends Activity {

    private WebView webView;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        webView = (WebView) findViewById(R.id.webView1);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("http://www.google.com");
    }
}

还有你的 XML:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>
于 2012-11-07T11:47:52.347 回答
6

看看这个,它对我有用......但我不知道它是否有任何副作用,但对我来说很好用

       super.onCreate(savedInstanceState);        
       WebView theWebPage = new WebView(this);
       theWebPage.getSettings().setJavaScriptEnabled(true);
       theWebPage.getSettings().setPluginState(PluginState.ON); 
       setContentView(theWebPage);
       theWebPage.loadUrl("http://www.hkmytravel.com");

源代码可在 [ http://www.androidpanna.com/functionality/webview-open-url-webpage-within-the-android-app-when-launch-android-development]中找到

于 2014-07-16T07:35:03.393 回答
0

测试以下内容:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>
于 2012-11-07T11:53:19.243 回答