我们如何在不打开浏览器的情况下在android应用程序中查看网页? [英] How can we view webpages in our android application without opening browser?

查看:110
本文介绍了我们如何在不打开浏览器的情况下在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>

这篇关于我们如何在不打开浏览器的情况下在android应用程序中查看网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆