Webview là một tiện ích nhúng vào giao diện ứng dụng dùng để hiển thị nội dung trang web từ một địa chỉ nào đó hoặc chuỗi HTML.
Để sử dụng webview bạn cần khai báo sử dụng quyền truy cập Internet. Khai báo trong mainifest nhé.
<uses-permission android:name="android.permission.INTERNET"/>
1) Tạo ứng dụng và nhúng webview vào layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WebViewActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/ed_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:onClick="ClickViewPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View page"/>
</LinearLayout>
<WebView
android:id="@+id/webview01"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>