Introdution to Android Webview:-
In the course of this tutorial, we will teach you how to use Android WebView and answer to some of the most common questions on android WebView.Android WebView is an embedded browser that can render static HTML data or even remote URL. A WebView is an android UI component that displays webpages.
In the course of this tutorial, we will teach you how to use Android WebView and answer to some of the most common questions on android WebView.Android WebView is an embedded browser that can render static HTML data or even remote URL. A WebView is an android UI component that displays webpages.
Xml Files:-
activity_webview.xml
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewSwitcher1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#dfd9c5">
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:layout_gravity="center"
android:gravity="center">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="18dp"
android:text="Enter Your Site"
android:textStyle="bold"
android:textColor="#000000"/>
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ems="10" >
</EditText>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:background="#000"
android:text="Go"
android:textColor="#fff" />
</RelativeLayout>
</TableLayout>
<TableLayout
android:id="@+id/tableLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="0dp" >
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</ViewSwitcher>
Java Files:-
WebviewActivity.java
package com.parthiv.androidwebviewexample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
public class WebviewActivity extends Activity {
EditText txtUrl;
String S;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview);
// button1 (Go)
Button btn1 = (Button) findViewById(R.id.button1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// editText1
txtUrl = (EditText) findViewById(R.id.editText1);
S = (txtUrl.getText().toString());
// webView1
WebView WebViw = (WebView) findViewById(R.id.webView1);
WebViw.loadUrl(S);
txtUrl.setText("");
}
});
}
keep Updating Every Day...
No comments:
Post a Comment