ad728

Monday, August 29, 2016

AIDE Tutorial - 20.2 WebView with back button




Java
package com.kc.webview3;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.webkit.*;

public class MainActivity extends Activity
{
private FrameLayout fl;
private ProgressBar pb;
private WebView web;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
   
web=(WebView) findViewById(R.id.web);
pb=(ProgressBar)findViewById(R.id.pb);
fl=(FrameLayout)findViewById(R.id.fl);




WebSettings WebSettings=web.getSettings();
WebSettings.setJavaScriptEnabled(true);
web.loadUrl("http://shyamkumarkc.blogspot.com");
web.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView View, String url){
fl.removeView(pb);
}
});



}
@Override
public void onBackPressed()
{
if(web.canGoBack()){
web.goBack();
}else{
// TODO: Implement this method
super.onBackPressed();
     }
}
}

Xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
android:id="@+id/fl">
    <WebView
        android:id="@+id/web"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

<ProgressBar
android:id="@+id/pb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
android:layout_gravity="center"/>

</FrameLayout>



Manifest
Add permission
<uses-permission android:name="android.permission.INTERNET"/>

Share:

2 comments:

  1. what is price if you make me webview with admobs ad baner ad and reward ad i want to make web browser you can help me

    ReplyDelete

Total Pageviews

Sponsor

Sponsor

ad300

Blog Archive