public class About extends AppCompatActivity {
WebView myWebView;
ProgressBar progressBar;
FrameLayout frameLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
Toolbar toolbar = findViewById(R.id.toolbar);
toolbar.setTitle("About CreativeGraphy");
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
progressBar = findViewById(R.id.progress_bar);
frameLayout = findViewById(R.id.frame_loading);
progressBar.setMax(100);
myWebView = findViewById(R.id.webview);
myWebView.loadUrl("http://www.google.co.in/");
myWebView.setWebViewClient(new HelpClient());
myWebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
frameLayout.setVisibility(View.VISIBLE);
progressBar.setProgress(newProgress);
setTitle("Loading....");
if (newProgress == 100) {
frameLayout.setVisibility(View.GONE);
//setTitle(View.getTitle());
}
super.onProgressChanged(view, newProgress);
}
});
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setVerticalScrollBarEnabled(false);
progressBar.setProgress(0);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
}//close activity when click back button
return super.onOptionsItemSelected(item);
}
public void onBackPressed() {
if (myWebView.canGoBack()) {
myWebView.goBack();
} else {
super.onBackPressed();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
if (myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
private class HelpClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
frameLayout.setVisibility(View.VISIBLE);
return true;
}
}
}
попробуйте, у него есть загрузка
макет
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".About">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:theme="@style/ToolbarColoredBackArrow" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/frame_loading"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="@id/app_bar"
android:background="@android:color/transparent">
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_gravity="top"
android:layout_marginTop="-3dp"
android:background="@android:color/transparent"
android:progress="20"
android:progressDrawable="@drawable/progress_cyclic" />
</FrameLayout>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/frame_loading" />
</RelativeLayout>
попробуйте использовать 2 веб-просмотра, если он загружен на 100%, другой, который был первым, останется, в то время как другие загружаются, когда онзагруженный второй веб-вид начинает загружаться