Reputation: 2098
I have an android tv 'wrapper' that will load a webapp using webview. It all loads fine using webview.loadUrl('someurl')
but whilst the page is loading, it's just a grey background.
What I wanted to do was first load a static file - which shows a loading spinner, and then load the main application, but doing this still makes the screen grey whilst the main app is loading.
Is there a simple way to either spin up a second webview ( seems wasteful ) - or to load one url (the file) and then the main remote url?
Upvotes: 0
Views: 1518
Reputation: 3016
I would have my xml layout like so:
<LinearLayout
android:id="@+id/loadingOrders"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/lato"
android:text="Loading..." />
<ProgressBar
android:id="@+id/pbLoading"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="150dp"
android:layout_height="wrap_content" />
</LinearLayout>
<WebView
android:id="@+id/webViewOrders"
android:layout_width="match_parent"
android:layout_height="match_parent" />
This displays the loading screen and then in the code when the webview is done loading, hide the LinearLayout
The code to check the loading is like so:
webViewOrders.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, final int newProgress) {
// UPDATE PROGRESS
pbLoading.setProgress(newProgress);
// CHECK IF FULLY LOADED
if (newProgress == 100) {
// HIDE VIEW
findViewById(R.id.loadingOrders).setVisibility(View.GONE);
}
}
});
Upvotes: 1