Advertisement here

Show Site With Android Webview

ANDROID PROGRAMMING : DISPLAY WEB PAGES WITH WEBVIEW


Menampilkan Situs dengan Webview Android Menampilkan Situs dengan Webview Android

12Eclipse Softwareor you can also useAndroid Studioplease choose which one you think is easy


Introduction to WebView

Web viewis an object that can display web pages much like a web browser. Web view can be used to display web pages on the internet or web pages contained in applications

In this webview application I willshowing UrlSite:http://www.helmykediri.comand my other blogs about the Mystery Blog, if you understand or are confused, we can just go to the tutorial:

How to Create a Simple WebView Android Programming :

1. Make somethingNew project in Eclipseit's up to you what name you want. chooseFile - New - Android Application Project

Menampilkan Situs dengan Webview Android Menampilkan Situs dengan Webview Android
Create a New Project
Name your project whatever you like. Use at least versionAndroid GingerbeardAPI 11

Menampilkan Situs dengan Webview Android Menampilkan Situs dengan Webview Android
Create Project
2. We makeUser Interfaceor how it looks, go tores/layout open activity_main.xml

Edit Main Activity XML

Then paste the following script on theactivity_main.xm l sectionXML

xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.Learnmultibannerhelmy.MainActivity" >


// to show text view


android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="HELMY KURNIAWAN"
        android:textAppearance="?android:attr/textAppearanceMedium" />

android:layout_width="match_parent"
android:layout_height="wrap_content"
        android:orientation="horizontal" >


// to create button


android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
        android:text="" />

android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
        android:text="Helmy Misteri" />



// to display the website


android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>


Here's how it looks inmode Activity_main.xml :

Menampilkan Situs dengan Webview Android Menampilkan Situs dengan Webview Android
XML Mode

Here's how it looks inGraphical Layout mode, I deliberately keep it simple:

Menampilkan Situs dengan Webview Android Menampilkan Situs dengan Webview Android
Graphic Display

3. EditMain_Activity.java, entersrc - com.example.blabla - MainActivity.java

Open with a click2xwill automatically open in the right window, then enter the script as follows:

package com.example.Belajarmultibannerhelmy;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class MainActivity extends ActionBarActivity
WebView webView;
Button button1, button2;
@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
       
webView = (WebView)findViewById(R.id.webView1);


  //Enable zoom in and zoom out controls on webview


webView.getSettings().setBuiltInZoomControls(true);


  //Activate java script on the opened web page


webView.getSettings().setJavaScriptEnabled(true);
button1 = (Button)findViewById(R.id.button1);
button2 = (Button)findViewById(R.id.button2);
button1.setOnClickListener(btnClick);
button2.setOnClickListener(btnClick);
       
View.OnClickListener btnClick = new View.OnClickListener()
@Override
public void onClick(View v)


              //Load URL according to clicked button


switch(v.getId())
case R.id.button1 :
webView.setWebViewClient(new ClientWebView());
webView.loadUrl("http://helmykkediri.blogspot.co.id" );
           
breaks;
case R.id.button2 :
webView.setWebViewClient(new ClientWebView());


            //load the web page contained in the android application


webView.loadUrl("http://mas-helmy.blogspot.co.id"); breaks;
           
           
;


           //display the previous web page if any (according to browsing history) when the back button is pressed


public boolean onKeyDown(int keyCode, KeyEvent event)
if((keyCode == event.KEYCODE_BACK) && webView.canGoBack())
webView.goBack(); return true;
           
return super.onKeyDown(keyCode, event);
           

           //forces to show the destination web page to Web View, not to Android's default browser


private class ClientWebView extends WebViewClient
               
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
return false;
               
               
               


4. Adduses permissiononAndroidManifest.xmlby including internet access as follows:

Menampilkan Situs dengan Webview Android Menampilkan Situs dengan Webview Android
Internet access
5. Done, please plug in your USB Smartphone and Run the project that has been created on the smart phone Right click the project - run as - android application

Menampilkan Situs dengan Webview Android Menampilkan Situs dengan Webview Android
Run Via USB



The result of the WebView that we have created is more or less like this:

Menampilkan Situs dengan Webview Android Menampilkan Situs dengan Webview Android
1
Menampilkan Situs dengan Webview Android Menampilkan Situs dengan Webview Android
2

If you want to download the raw versionbefore compilinginto the Android APK application file, please download via the link below:
Or please download the project that has been compiled into the APK, you just have to run your Android Smartphone:


That's the articleAndroid Programming Creating a simple Webview, hopefully useful if there is something you want to ask please ask in the comment box . My previous postCREATING CRUD Buying and Selling Clotheson the Android Application. That is all and thank you
Next Post Previous Post
No Comment
Add Comment
comment url
Android