webview.settings.displayZoomControls = false
webview.loadUrl("http://www.joklinztech.com")
webview.webViewClient = WebViewClient()
webview.webChromeClient = object : WebChromeClient() {
override fun onProgressChanged(view: WebView?, newProgress: Int) {
super.onProgressChanged(view, newProgress)
val loadingProgressBar = findViewById<View>(R.id.progressBar2) as ProgressBar
loadingProgressBar.progress = newProgress
//loadingTitle.setProgress(newProgress);
// hide the progress bar if the loading is complete
if (newProgress == 100) {
loadingProgressBar.visibility = View.GONE
webview.visibility = View.VISIBLE
} else {
loadingProgressBar.visibility = View.VISIBLE
}
}
}
}
else
{
alert("please exit app","No Internet Connection ")
{
yesButton { finish() }
noButton {toast("no internet connection")}
}.show()
}
}
override fun onBackPressed() {
val webview = findViewById<View>(R.id.WebView) as WebView
if(webview.canGoBack()) {
webview.goBack()
} else {
super.onBackPressed()
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
// Inflate the menu; this adds items to the action bar if it is present.
menuInflater.inflate(R.menu.menu_main, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
val id = item.itemId
if (id == R.id.action_settings) {
email("wise4rmgod@gmail.com")
}
if (id == R.id.action_setting) {
finish()
}
if (id == R.id.action_settin) {
share("Joklinztech is a tech community that will keep you up to date with all the tech infos in 9ja " +
"and across the world,our services include android tutorials using kotlin,graphics" +
" design,animation,web designing/development","Joklinztech the home for young techz")
}
return super.onOptionsItemSelected(item)
}
}
XML SECTION
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.andela.smithnwokocha.joklintechapp.MainActivity">
<!-- view for AdMob Banner Ad -->
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
tools:layout_editor_absoluteX="167dp"
tools:layout_editor_absoluteY="215dp" />
<WebView
android:id="@+id/WebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/adView"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:visibility="gone">
</WebView>
</RelativeLayout>
No comments:
Post a Comment