【发布时间】:2020-08-31 04:32:59
【问题描述】:
我想在 webview 中加载网站,但使用时,不显示。 我想在 webview 中加载这个网站 web.rubika.ir 并发送请求。 我该怎么做呢?只有这个网站。
【问题讨论】:
我想在 webview 中加载网站,但使用时,不显示。 我想在 webview 中加载这个网站 web.rubika.ir 并发送请求。 我该怎么做呢?只有这个网站。
【问题讨论】:
您可以使用它在您的 webView 中加载一个 url
webView.loadUrl("Your URL Here")
此外,如果您想在您的网址是否仍在加载或完成时收到通知,您可以查看此get notified when webview loaded。
您可以在加载 url 时显示进度条,这将有助于了解 web 视图正在加载。
【讨论】:
在此活动的布局文件 (.xml) 中,使用 webview 小部件
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
然后在activity的onCreate方法中,使用webview。
WebView wv;
wv = findViewById(R.id.webview);
wv.loadUrl("web.rubika.ir");
如果你想启用 javascript 支持
WebSettings webSettings = wv.getSettings();
webSettings.setJavaScriptEnabled(true);
确保您已在 manifest.xml 中声明 Internet 权限
<uses-permission android:name="android.permission.INTERNET" />
然后在你清单的 Application 标签中添加这个;
<application
android:usesCleartextTraffic="true"
6.完成。
【讨论】: