https://github.com/miguelsavignano/android-hybrid-webview
Simple web view
https://github.com/miguelsavignano/android-hybrid-webview
android example
Last synced: about 1 month ago
JSON representation
Simple web view
- Host: GitHub
- URL: https://github.com/miguelsavignano/android-hybrid-webview
- Owner: MiguelSavignano
- Created: 2016-04-28T15:18:28.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-04-20T22:44:25.000Z (about 7 years ago)
- Last Synced: 2025-05-31T04:07:17.785Z (about 1 year ago)
- Topics: android, example
- Language: Kotlin
- Homepage:
- Size: 186 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Hybrid WebView App
Convert website in android apk.
## Change web url
open file `app/src/main/java/com.example.webview/MainActivity.kt` and change the WEB_URL const
```
const val WEB_URL = "https://my-responsive-website"
```
## Create icon
Using Android studio
ImportFile > New > Image Asset
or copy the new icon in all mipmap folders
```
cp ic_launcher.png ./app/src/main/res/mipmap*
```
## Build app
Apk path
```
/app/build/outputs/apk/debug/app-debug.apk
```
### Override webview
In hybrid webview you nedd to simulate a native application you can override some content of the webpage injenting javascript.
onPageFinished run the script src/main/res/assets/initJavascript.js to override header, footer and change eventlisteners.
EJ:
```javascript
$("header") && $("header").remove();
$("footer") && $("footer").remove();
```
### Native events
Listener javascript events in native code.
The global Object "Android" help to comunicate webview with native code.
Example:
- Native
```java
class WebAppInterface(private val mContext: Context) {
@JavascriptInterface
fun showToast(toast: String) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show()
}
}
```
- Webview
```javascript
Android.showToast("Hello world!!!");
```