Pemrograman Mobile : Web Kit
Universitas Udayana
Fakultas Teknik
Teknologi Informasi
package
com.example.krisnaadinatha.bukaweb;
import
android.app.Activity;
import
android.graphics.Bitmap;
import
android.os.Bundle;
import
android.view.Menu;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.webkit.WebView;
import
android.webkit.WebViewClient;
import
android.widget.Button;
import
android.widget.EditText;
public class
BukaWeb extends Activity { private
WebView webView; private EditText
urlEditText;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.buka_web);
urlEditText = (EditText)
findViewById(R.id.urlField);
webView = (WebView)
findViewById(R.id.webView);
Button openUrl = (Button)
findViewById(R.id.goButton);
openUrl.setOnClickListener(new
OnClickListener() {
@Override
public void onClick(View view) {
String url =
urlEditText.getText().toString();
if(validateUrl(url)){
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(url);
}
}
private boolean
validateUrl(String url) {
return true;
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu
menu) {
getMenuInflater().inflate(R.menu.buka_web, menu);
return true;
}
}
|
<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=".bukaweb" >
<LinearLayout
android:id="@+id/urlContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:id="@+id/urlField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="Enter URL to
open" />
<Button
android:id="@+id/goButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Open"
/>
</LinearLayout>
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@id/urlContainer" />
</RelativeLayout>
|
<?xml
version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.krisnaadinatha.bukaweb">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".BukaWeb">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission
android:name="android.permission.INTERNET" />
</manifest>
|
Sumber : Modul Pembelajaran Pemrograman Aplikasi Berbasis Android // I Putu Agus Eka Pratama, ST.MT.