在android中的webView中打开URL

时间:2012-11-07 11:42:10

标签: java android webview

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

3 个答案:

答案 0 :(得分:25)

的活动:

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"
/>

答案 1 :(得分:5)

看看这个, 它对我有用...但我不知道它是否有任何副作用,但与我合作

       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]

中找到

答案 2 :(得分: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"
/>