我们如何在不打开浏览器的情况下在android应用程序中查看网页?

我们如何在不打开浏览器的情况下在android应用程序中查看网页?

问题描述:

嘿,我正在开发一个android应用程序,我想在该应用程序内连接到Web.但是我已经尝试WebView到一定程度,但是它的显示文件在我的目录中很好,但是当连接到google.com时,它显示错误!

Hey i am developing an android application , and i want to connect to web inside that application. However i have tried WebView to someextent but its displaying file's on my directory fine but when connecting to google.com it display's an error !

然后我添加了此文件 <uses-permission android:name="android.permission.INTERNET" />

Then i added this file <uses-permission android:name="android.permission.INTERNET" />

在我的Manifest.xml中,现在在浏览器中显示了url(google.com) 任何有关如何打开应用程序内浏览器的帮助吗?

in my Manifest.xml and now the the url(google.com) is being displayed in the browser Any help how i can open the browser inside my application ?

使用网络视图.

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

public class WebViewDemo extends Activity 
{
    private WebView mWebView = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

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

在清单文件中添加<uses-permission android:name="android.permission.INTERNET" />.

此处使用的main.xml文件.

main.xml file which used here.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<WebView  
        android:id="@+id/webView"
        android:scrollbars="none" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    />
</LinearLayout>