1) First create a new project in android studio more details...
2) Open activity_main.xml file under the layout folder.
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
When you add the code to activity_main.xml you can see the preview by clicking Design.
4) You must set internet permission in AndroidManifest.xml. Open AndroidManifest.xml file and enter the following code.
<uses-permission android:name="android.permission.INTERNET" />
5) Open MainActivity.java file and modify it by the below steps.
a) import the following class
import android.webkit.WebView;
import android.webkit.WebViewClient;
b) When you want to load the url to your webview, just call the below code.
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("http://www.google.com");
6) Now you are done with your first webview, just run the code.
0 nhận xét:
Đăng nhận xét