WebView with stylish Progress Bar
Add this line in Manifests
Internet Permission
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
use this line code in manifest.
in Applicatin tag
Http to https
android:usesCleartextTraffic="true"
Lottie Animation For Stylish Progress Bar.
Lottie Dependencies Use Build.gradle
Lottie Dependencies
//Lottie anim
implementation "com.airbnb.android:lottie:3.4.0"
add this code in webview activity.xml Example : activity_main.xml
You must use this code in RelativeLayout
activity_main.xml
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<com.airbnb.lottie.LottieAnimationView
android:visibility="invisible"
android:layout_centerInParent="true"
android:id="@+id/loading"
android:layout_width="130dp"
android:layout_height="130dp"
app:lottie_rawRes="@raw/loading"
app:lottie_autoPlay="true"
app:lottie_loop="true"/>
Java Code Use this code in java
Java for stylish Progress bar
public class MainActivity extends AppCompatActivity {
WebView webview;
LottieAnimationView loading;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
webview = findViewById(R.id.webview);
loading = findViewById(R.id.loading);
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
webview = (WebView) findViewById(R.id.webview);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
//Make the bar disappear after URL is loaded, and changes string to Loading...
//setTitle("Loading...");
setProgress(progress * 100); //Make the bar disappear after URL is loaded
// Return the app name after finish loading
if(progress == 100){
loading.setVisibility(View.INVISIBLE);
}else {
loading.setVisibility(View.VISIBLE);
}
}
});
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("http://www.google.com");
}// OnCreate method Close Here =======================
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
} // Public Class Close Here===============
If you don't know how to implement this please watch this video
Clicking on the button shows the video of the loading animation