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 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;
}
}
}
Tags:
Android Studio
