Loading/Splash Screen for WebView in Android Studio
Steven Sohcot
14515

I’m going through the same problem, only I use the crosswalk webview. Can someone help me ?

Wanted to load the ulr along with the splash, so at the time of transition from the splash to the url the site has already been loaded.

I’ll put my code below:

MainActivity.java

package ovortex.com.crosswalkwebview;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ProgressBar;
import org.xwalk.core.XWalkActivity;
import org.xwalk.core.XWalkPreferences;
import org.xwalk.core.XWalkResourceClient;
import org.xwalk.core.XWalkView;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends XWalkActivity {
private XWalkView mWebview;
    SwipeRefreshLayout mySwipeRefreshLayout;
ProgressBar loadingImage;
    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mWebview=(XWalkView)findViewById(R.id.xwalkWebView);
        // turn on debugging
XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);

        //Get status of swipe layout in Strings.xml and enable or disable.
String swipe = getString(R.string.enable_swipe);
if("1".equals(swipe)) {
mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
mySwipeRefreshLayout.setEnabled(false);
mySwipeRefreshLayout.setOnRefreshListener( new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
mySwipeRefreshLayout.setEnabled(false);
mySwipeRefreshLayout.setRefreshing(false);
swipeProgress();
}
}
);
}else{
mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
mySwipeRefreshLayout.setEnabled(false);
}
        mWebview.setResourceClient(new XWalkResourceClient(mWebview){
public void onProgressChanged(XWalkView view, int progress) {
if (progress == 100) {
//hide loadImage
//loadingImage.setVisibility(View.INVISIBLE);
                    //String swipe = getString(R.string.enable_swipe);
//if("1".equals(swipe)) {mySwipeRefreshLayout.setEnabled(true);}
} else {
// mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
//Disable swipe
// mySwipeRefreshLayout.setEnabled(false);
//show loadImage
// loadingImage.setVisibility(View.VISIBLE);
}
}
});

    }
            @Override
protected void onXWalkReady() {
// Do anything with embedding API
mWebview.loadUrl("http://player.pipocaplayfm.com/new-releases");
}

    //Call swipe layout
public void swipeProgress(){
mWebview.setResourceClient(new XWalkResourceClient(mWebview){
public void onProgressChanged(XWalkView view, int progress) {
if (progress == 100) {
//hide loadImage
loadingImage.setVisibility(View.INVISIBLE);
                    String swipe = getString(R.string.enable_swipe);
if("1".equals(swipe)) {mySwipeRefreshLayout.setEnabled(true);}
} else {
mySwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
//Disable swipe
mySwipeRefreshLayout.setEnabled(false);
//show loadImage
loadingImage.setVisibility(View.VISIBLE);}
}
});
}

}

SplashScreenActivity.java

package ovortex.com.crosswalkwebview;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
/**
* Created by Admin on 24/06/2017.
*/
public class SplashScreenActivity extends AppCompatActivity {
    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
        Handler handle = new Handler();
handle.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreenActivity.this,
MainActivity.class);
startActivity(intent);
                finish();
}
}, 6000);//define o tempo
        getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
    }

}

activity_main.xml

<?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"
tools:context=".MainActivity"
>


<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>

<org.xwalk.core.XWalkView
android:id="@+id/xwalkWebView"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
>

</org.xwalk.core.XWalkView>

</android.support.v4.widget.SwipeRefreshLayout>

</RelativeLayout>

activity_splash_screen.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:orientation="vertical"
android:gravity="center"
>

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:src="@drawable/novosplash"
/>


</LinearLayout>
Like what you read? Give jhonatan santos a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.