Skip to content

Instantly share code, notes, and snippets.

@ahmmedrejowan
Created January 12, 2022 18:59
Show Gist options
  • Save ahmmedrejowan/05edbdad8e9b83a4cc98bd20ad29b36c to your computer and use it in GitHub Desktop.
Save ahmmedrejowan/05edbdad8e9b83a4cc98bd20ad29b36c to your computer and use it in GitHub Desktop.
WebView with SwipeRefreshLayout
public class Web extends AppCompatActivity {
WebView mWebView;
SwipeRefreshLayout swipeRefreshLayout;
final Activity activity = this;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.activity_web);
swipeRefreshLayout = findViewById(R.id.swipeRefresh);
mWebView = findViewById(R.id.WebView);
mWebView.loadUrl(url);
mWebView.setWebChromeClient(new chromeView());
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
swipeRefreshLayout.setRefreshing(false);
mWebView.reload();
}
});
}
public class chromeView extends WebChromeClient {
@Override
public void onProgressChanged(WebView webView, int i) {
activity.setTitle(" Loading ...");
activity.setProgress(i * 100);
if (i < 100) {
swipeRefreshLayout.setRefreshing(true);
} else if (i == 100) {
activity.setTitle("Whatsapp Web");
swipeRefreshLayout.setRefreshing(false);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment