Skip to content

Instantly share code, notes, and snippets.

@piruin
Created February 24, 2016 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piruin/c8d9b79f4dcf7b9a1d8d to your computer and use it in GitHub Desktop.
Save piruin/c8d9b79f4dcf7b9a1d8d to your computer and use it in GitHub Desktop.
Web View Test
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.webViewTest"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="MyActivity"
android:theme="@android:style/Theme.Holo.Light.Dialog"
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>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MyActivity"
/>
<WebView
android:layout_width="match_parent"
android:layout_height="300dp"
android:minHeight="300dp"
android:id="@+id/webView" android:layout_gravity="center_horizontal"/>
</LinearLayout>
package com.example.webViewTest;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
public class MyActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView = (WebView) findViewById(R.id.webView);
webView.setWebViewClient(new TBRWebViewClient());
webView.loadUrl("http://www.tamis.in.th");
}
public class TBRWebViewClient extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals("http://localhost"))
Toast.makeText(MyActivity.this, "do something here", Toast.LENGTH_LONG).show();
else
Toast.makeText(MyActivity.this, "url " + url, Toast.LENGTH_LONG).show();
return super.shouldOverrideUrlLoading(view, url);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment