Your experience on this site will be improved by allowing cookies
WebVeiw in android
To display a web page in android loaded from the same application or URL, the WebView is used in Android. Thus, online content can be displayed in an Android activity using the Android WebView which displays a web page using the Webkit engine. In Android, the AbsoluteLayout class has a subclass android.webkit.WebView.
To load and display a web page, the Android WebView class uses its loadUrl() and loadData() methods.
To display a web page using WebView:
WebView mywebview = (WebView) findViewById(R.id.webView1); mywebview.loadUrl("https://www.w3schools.blog/"); |
To display an HTML web page using WebView:
For this, we need to locate the HTML file inside the asset directory.
WebView mywebview = (WebView) findViewById(R.id.webView1); mywebview.loadUrl("file:///android_asset/myresource.html"); |
To display an HTML code of a string:
String data = " | "; mywebview.loadData(data, "text/html", "UTF-8"); |
activity_main.xml:
The web page (.html, .jsp) needs to be placed in the assets folder, to add it locally in an application. To create an assets folder follow the below steps: right-click on app -> New -> Folder -> Assets Folder ->main OR Create an assets directory inside the main directory. Activity class: (File: MainActivity.java)
|
0 comments