Skip to content

Instantly share code, notes, and snippets.

@rudyryk
Created May 15, 2015 05:06
Show Gist options
  • Save rudyryk/77ccd0e06e815a09c761 to your computer and use it in GitHub Desktop.
Save rudyryk/77ccd0e06e815a09c761 to your computer and use it in GitHub Desktop.
Silver - basic sample for WebView on Android
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hellofire">
<!-- the android:debuggable="true" attribute is overwritten by the compiler when the debug info option is set -->
<uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:label="@string/app_name"
android:icon="@drawable/icon"
android:debuggable="true">
<activity android:label="@string/app_name" android:name="com.example.hellofire.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="4" />
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" >
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
import java.util
import android.app
import android.content
import android.os
import android.util
import android.view
import android.widget
import android.webkit
public class MainActivity: Activity {
public override func onCreate(savedInstanceState: Bundle!) {
super.onCreate(savedInstanceState)
ContentView = R.layout.main
let web: WebView = findViewById(R.id.webview) as! WebView
web.setWebViewClient(MyWebViewClient())
web.loadUrl("http://httpbin.org/get")
}
}
public class MyWebViewClient : WebViewClient {
public override func onPageStarted(_ view: WebView!, _ url: String!, _ favicon: android.graphics.Bitmap!) {
Log.d("onpage " , url)
}
public override func shouldOverrideUrlLoading(_ view: WebView!, _ url: String!) -> Bool {
Log.d("Loading" , url)
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment