Kurumsal Firma Scripti | Alkinoe

Kombi Bakım Servisi Scripti | Alkimedon

Tesisatçı Web Scripti | Alkestis

Spor Salonu Sitesi Scripti | Alkathoos

Android WebView Example

  • Android Programming
  • Savaş Dersim Çelik
  • Monday July 17th, 2017
  • 3,000 Görüntülenme
  • JAVA
  • Mobile

Android WebView is used to display web page in android. The web page can be loaded from same application or URL. It is used to display online content in android activity.

Android WebView uses webkit engine to display web page.

The android.webkit.WebView is the subclass of AbsoluteLayout class.

The loadUrl() and loadData() methods of Android WebView class are used to load and display web page.

Let’s see the simple code to display javatpoint.com web page using web view.

WebView mywebview = (WebView) findViewById(R.id.webView1);  
mywebview.loadUrl("http://www.javatpoint.com/");

Let’s see the simple code to display HTML web page using web view. In this case, html file must be located inside the asset directory.

WebView mywebview = (WebView) findViewById(R.id.webView1);  
mywebview.loadUrl("file:///android_asset/myresource.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");
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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>
MainActivity.java
import android.os.Bundle;
import android.app.Activity;
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://webinyo.com/");
    }
}
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>

 

Yorumlar

Yazıya 1 yorum yapılmış.

Erdoğan Friday July 27th, 2018

Meğer bu kadar basitmiş, yazılımcılar bi ton ücret istiyor bunun için? farklı bir yöntem mi kullanıyorlar acaba.

Benzer İçerikler