Web View
Web View
The web view is used to load the website directly into our app.
<uses-permission android:name=”android.permission.INTERNET”/>
2.activity_main.xml
<LinearLayout
android:orientation=”vertical”>
<RelativeLayout
android:layout_width=”wrap_content”
android:layout_width=”match_parent”>
<Button
android:id=”@+id/b1”
android:layout_width=”48dp”
android:layout_height=”warp_content”
//We can’t specify the < or > symbols directly. Right-click bulb Extract string
resource Resource name =”back” Ok. Now android:text=”@string/back”
comes into the xml file.
android:text=”<”/>
<Button
android:id=”@+id/b2”
android:layout_width=”48dp”
android:layout_height=”warp_content”
//We can’t specify the > symbol directly. Right-click bulb Extract string resource
Resource name =”next” Ok. Now android:text=”@string/next” comes into
the xml file.
android:text=”>”/>
<Button
android:id=”@+id/b3”
android:layout_width=”48dp”
android:layout_height=”warp_content”
//We can’t specify the > symbol directly. Right-click bulb Extract string resource
Resource name =”go” Ok. Now android:text=”@string/go” comes into the
xml file.
android:text=”go”/>
<EditText
android:id=”@+id/et1”
android:layout_width=”48dp”
android:maxLines=”1”
android:layout_height=”warp_content”/>
</RelativeLayout>
<WebView
android:id=”@+id/wv1”
android:layout_width=”match_parent”
android:layout_height=”warp_content”/>
</LinearLayout>
3. MainActivity.kt
super.onCreate(b)
setContentView(R.layout.activity_main)
btngo.setOnClickListener({
web.loadUrl(“https:// “ + url.text.toString())
})
btnback.setOnClickListener({
if(web.canGoBack())
web.goBack()
else
})
btnforward.setOnClickListener({
if(web.canGoForward())
web.goForward()
else
})