gpt4 book ai didi

android - 有人可以给出一个在 android 中实现 webview 的确切示例吗?

转载 作者:可可西里 更新时间:2023-11-01 18:45:39 25 4
gpt4 key购买 nike

您好,我正在使用 WebView 实现开发 android 应用程序。

我关注了 official android tutorial .

我在 eclipse 中构建我的项目时没有遇到错误,但是在运行应用程序时:

the application has stopped working unexpectedly

最佳答案

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

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 文件应该是这样的:

<?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/> 之后的 list 中使用以下内容:

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

关于android - 有人可以给出一个在 android 中实现 webview 的确切示例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8614553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com