5
votes

i have a splash screen at start up. with the following coding

public class Splash extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
    Thread logoTimer = new Thread(){
        public void run(){
            try{
                int logoTimer = 0;
                while (logoTimer<5000){
                    sleep(100);
                    logoTimer=logoTimer+100;
                     }
                startActivity(new Intent("com.package.MAIN"));
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
            finally{
                finish();
            }
        }
    };
    logoTimer.start();
}}

now i just want to add a horizontal progress bar to the above splash activity say at the bottom of the screen.. so as the splash screen appears simultaneously the progress bar should load and when it finishes the next activity should appear.

searched few examples on progress bar but was not able to do what i want. there were many examples for progress bar with a dialog box. but here i don't want any dialog box. i just need a plain horizontal progress bar on my splash screen.

so can someone help me out with required coding and stuffs? pls ! :)

2
Don't use 'splash screens' just for the sake of it. At the very least a 'splash screen' might be of use when performing a time consuming task but even then they're usually unnecessary. Yours serves no purpose other than to delay the user's access to your app by 5 seconds as far as I can tell. Not good for the UX. See this blog for why...android.cyrilmottier.com/?p=632Squonk
Do you know how to measure loading progress? A progress bar is pointless if you cannot update it meaningfully every 10% or so.Seva Alekseyev
I answered this question in below link. stackoverflow.com/a/45020909/4896539Brayan Loayza

2 Answers

8
votes

Here you go, wrote a tutorial how to create a SplashScreen with a progress bar:

http://blog.blundellapps.com/tut-splashscreen-with-progress-bar/

Basically instead of your thread it starts an ASyncTask, you pass a reference to your progressSpinner into the ASyncTask and this will update it as the thread is downloading resources (or whatever you want to do)

0
votes

This XML example will create a horizontal ProgressBar:

<ProgressBar
    android:id="@+id/progress_bar"
    style="@android:style/Widget.ProgressBar.Horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:progress="0" />