Created
February 24, 2016 08:43
-
-
Save piruin/c8d9b79f4dcf7b9a1d8d to your computer and use it in GitHub Desktop.
Web View Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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