Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

NAMA : CUT MUTIARA TAHER

NIM : 2203025574
WEBVIEW LOKAL HTML
1. 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"
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.webviewlokalhtml.MainActivity"
>

<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />

</RelativeLayout>

2. MainActivity.java
package com.example.webviewlokalhtml;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class MainActivity extends Activity {

WebView wV;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

wV = findViewById(R.id.webView1);
WebSettings wS = wV.getSettings();
wS.setBuiltInZoomControls(true);
wS.setJavaScriptEnabled(true);
wV.loadUrl("file:///android_assets/pertama.html");
}
}

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.ma
in), (v, insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top,
systemBars.right, systemBars.bottom);
return insets;
});
}
}

3. Pertama.html
<html>
<head></head>
<body>
<h1> File Html Local</h1></br>
<h2> Halaman Pertama</h2>
</body> </html>

You might also like