Reading
Add Comment
Android WebView Example Code
Android WebView is utilized to show site page in android. The page can be stacked from same application or URL. It is utilized to show online substance in android movement.
Android WebView utilizes webkit motor to show website page.
The android.webkit.WebView is the subclass of AbsoluteLayout class.
The loadUrl() and loadData() techniques for Android WebView class are utilized to load and showcase website page.
Let's see the simple code to display dheeruapps.blogspot.in web page using web view.
WebView mywebview = (WebView) findViewById(R.id.webView1);
mywebview.loadUrl("http://dheeruapps.blogspot.in/");
How about we see the straightforward code to show HTML website page utilizing web view. For this situation, html record must be situated inside the benefit registry.
WebView mywebview = (WebView) findViewById(R.id.webView1);
mywebview.loadUrl("file:///android_asset/index.html");
mywebview.loadUrl("file:///android_asset/index.html");
Let's see another code to display HTML code of a string.
String data = "<html><body><h1>Hello, Javatpoint!</h1></body></html>";
mywebview.loadData(data, "text/html", "UTF-8");
mywebview.loadData(data, "text/html", "UTF-8");
Android WebView Example
activity_main.xml
File: activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp" />
</RelativeLayout>
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="42dp" />
</RelativeLayout>
Activity class
File: MainActivity.java
package com.dheeruapps.webview;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mywebview = (WebView) findViewById(R.id.webView1);
//mywebview.loadUrl("http://www.javatpoint.com/");
/*String data = "<html><body><h1>Hello, Javatpoint!</h1></body></html>";
mywebview.loadData(data, "text/html", "UTF-8"); */
mywebview.loadUrl("http://dheeruapps.blogspot.in/");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mywebview = (WebView) findViewById(R.id.webView1);
//mywebview.loadUrl("http://www.javatpoint.com/");
/*String data = "<html><body><h1>Hello, Javatpoint!</h1></body></html>";
mywebview.loadData(data, "text/html", "UTF-8"); */
mywebview.loadUrl("http://dheeruapps.blogspot.in/");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
0 comments:
Post a Comment