Breaking News
Loading...

How to add a splash screen in an android application

7:07 PM

Everyone wants his/her application to be beautiful and attractive for an eye of a user. And there are a lot of applications, at least desktop applications, mostly games that use splash screens. It’s nice and, moreover, while the splash screen is working, you can initialize your application. Many tutorials exist explaining how to begin Android programming and I won't repeat them here. You can find them all over the internet. So I will show only the programming stuff.


Activity class
---------------
public class SplashScreen extends Activity {
private final int DISPLAY_LENGTH = 2000; // splash screen duration
private ProgressBar mProgressBar;

@Override
public void onCreate(Bundle si) {
super.onCreate(si);
// removing status bar in
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.splash);
mProgressBar=(ProgressBar)findViewById(R.id.xPbSplash);
// setting progress bar
mProgressBar.setVisibility(ProgressBar.VISIBLE);

// created handler for waiting
// post delayed to wait some time before going to next intenet

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent login = new Intent(SplashScreen.this, HomeScreen.class);

SplashScreen.this.startActivity(login);
mProgressBar.setVisibility(ProgressBar.INVISIBLE);
SplashScreen.this.finish();
}

}, DISPLAY_LENGTH);
}

}


xml for UI
--------------

android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/bg" android:orientation="vertical">
android:layout_height="60dip" android:background="@drawable/logo"
android:layout_centerInParent="true" />
android:layout_width="50dip" android:layout_height="50dip"
android:layout_centerInParent="true" android:indeterminateOnly="true" />




0 komentar:

Post a Comment

 
Toggle Footer