Created
January 12, 2022 18:59
-
-
Save ahmmedrejowan/05edbdad8e9b83a4cc98bd20ad29b36c to your computer and use it in GitHub Desktop.
WebView with SwipeRefreshLayout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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