有人可以给出一个在 android 中实现 webview 的确切示例吗 [英] Can someone give one exact example of webview implementation in android

查看:24
本文介绍了有人可以给出一个在 android 中实现 webview 的确切示例吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 WebView 实现开发 android 应用程序.

Hi I am developing android application using WebView implementation.

我遵循了官方安卓教程.

在 Eclipse 中构建项目时没有出现错误,但在运行应用程序时没有出现错误:

I am not getting errors when building my project in eclipse, but when running the application :

应用程序意外停止工作

推荐答案

你的 Java 文件应该是这样的:

Your Java file should be like this:

public class WebViewSampleActivity extends Activity {
     WebView wb;
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    }
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);      
        wb=(WebView)findViewById(R.id.webView1);        
        wb.getSettings().setJavaScriptEnabled(true);
        wb.getSettings().setLoadWithOverviewMode(true);
        wb.getSettings().setUseWideViewPort(true);
        wb.getSettings().setBuiltInZoomControls(true);
        wb.getSettings().setPluginState(WebSettings.PluginState.ON);
        wb.getSettings().setPluginsEnabled(true);           
        wb.setWebViewClient(new HelloWebViewClient());
        wb.loadUrl("http://www.examplefoo.com");        
    }
}

你的xml文件应该是这样的:

Your xml file should be like this:

<?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" 
    android:layout_gravity="center">

    <WebView
        android:id="@+id/webView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center" />

</LinearLayout>

在清单中的 之后使用以下内容:

Use the following in your manifest after <uses-sdk><uses-sdk/>:

 <uses-permission android:name="android.permission.INTERNET"/>

这篇关于有人可以给出一个在 android 中实现 webview 的确切示例吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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