Adding web pages
Including a single web page in an activity or fragment using the WebView class is almost as simple as adding any other kind of view. There are three easy steps, as follows:
- Add the following permission to the manifest:
<uses-permission android:name="android.permission.INTERNET" />
- The
WebView
itself looks like this:<WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/web_view" android:layout_width="match_parent" android:layout_height="match_parent" />
- Finally, the Java for adding page is as follows:
WebView webView = (WebView) findViewById(R.id.web_view); webView.loadUrl("https://www.packtpub.com/");
That's all there is to it, although you would probably want remove or reduce the default 16dp margins for most pages.
![Adding web pages](https://static.packt-cdn.com/products/9781786467218/graphics/graphics/image_12_001.jpg)
This system is ideal for when dealing with pages that have been specifically designed for our app. If want to send our user to...