Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Browser">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/wv"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
MainActivity.java
package com.mycompany.myapp2;
import android.app.*;
import android.os.*;
import android.webkit.*;
import android.widget.*;
import android.support.v4.widget.*;
import android.view.*;
import android.content.*;
public class MainActivity extends Activity
{WebView wv;
SwipeRefreshLayout swipe;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(
setContentView(R.layout.main);
wv=(WebView)findViewById(R.id.
swipe = (SwipeRefreshLayout)
wv.loadUrl("https://
WebSettings webSettings = wv.getSettings();
webSettings.
wv.getSettings().
swipe.setRefreshing(true);
wv.setWebViewClient(new WebViewClient(){
public void onPageFinished (WebView view, String url){
swipe.setRefreshing(false);
}
});
swipe.setOnRefreshListener(new SwipeRefreshLayout.
@Override
public void onRefresh() {
wv.reload();
}
});
}
@Override
// Detect when the back button is pressed
public void onBackPressed() {
if(wv.canGoBack()) {
wv.goBack();
} else {
AlertDialog.Builder builder=new AlertDialog.Builder(
builder.setMessage("Are you sure you want to exit?");
builder.setIcon(android.R.
builder.setPositiveButton("
@Override
public void onClick(DialogInterface dialog, int which)
{
MainActivity.this.finish();
}
});
builder.setNegativeButton("No"
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.cancel();
}
});
AlertDialog alert =builder.create();
alert.show();
}
}
}
Manifest
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>