您可以WebView在布局中渲染.WebView例如,这可以指向远程或本地资源,例如HTML/JS/CSS文件.
以下是如何在布局中声明Webview:
<WebView
android:id="@+id/mywebview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
Run Code Online (Sandbox Code Playgroud)
并在代码中使用/初始化它:
/* Retrieve your webview and manipulate it using a reference to
the object created in your XML */
WebView webview = (WebView) this.findViewById(R.id.mywebview);
/* If you would like to use Javascript in your view */
webview.getSettings().setJavaScriptEnabled(true);
/* Load the URL to the resource you want to load in your view */
webview.loadUrl("http://hostname/...");
Run Code Online (Sandbox Code Playgroud)