有人可以举一个在Android中实现Webview的确切例子吗 [英] Can someone give one exact example of webview implementation in android
本文介绍了有人可以举一个在Android中实现Webview的确切例子吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用WebView
实现开发android应用.
Hi I am developing android application using WebView
implementation.
我遵循了官方android教程.
在eclipse中构建项目时,我没有遇到错误,但是在运行应用程序时:
I am not getting errors when building my project in eclipse, but when running the application :
应用程序意外停止运行
the application has stopped working unexpectedly
推荐答案
您的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>
在<uses-sdk><uses-sdk/>
之后的清单中使用以下内容:
Use the following in your manifest after <uses-sdk><uses-sdk/>
:
<uses-permission android:name="android.permission.INTERNET"/>
这篇关于有人可以举一个在Android中实现Webview的确切例子吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文