Posted by : Unknown
Minggu, 17 Desember 2017
Untuk membuat webView kita harus setting 3 file yaitu
-MainActivity.java
-main.xml
-AndroidManifest.xml
-MainActivity.java
-main.xml
-AndroidManifest.xml
untuk main.xml isikan script ini
Sesuaikan id nya dengan nama id di file MainActivity.java
Sesuaikan id nya dengan nama id di file MainActivity.java
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webViewApp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webViewApp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
</LinearLayout>
Kemudian Untuk MainActivity.java
Perhatikan dengan baik di bagian import dan package sesuaikan
package com.melki.droid;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView web = (WebView) findViewById(R.id.webViewApp);
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient(){
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient(){
public boolean shoulOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
});
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
});
web.loadUrl("http://melki-art.blogspot.com");
}
}
}
}
AndroidManifest.xml anda perlu menambahkan code ini didalamnya
<uses-permission android:name="android.permission.INTERNET"/>
Seperti ini
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</intent-filter>
</activity>
</application>
</manifest>
Selamat Mencoba