开发者

How to Display a progress bar that displays over the fade screen overlapping the previous activity

开发者 https://www.devze.com 2023-04-12 07:05 出处:网络
I am trying to create an ac开发者_如何学编程tivity. I have made some controls in that activity. Suppose, I click on some control(e.g Button), then a fade screen display that overlaps the previous acti

I am trying to create an ac开发者_如何学编程tivity. I have made some controls in that activity. Suppose, I click on some control(e.g Button), then a fade screen display that overlaps the previous activity and over the fade screen there is a progress bar. when the progress bar is 100% completed, then the fade screens disappear and the next activity displays.

Now my question is, How can I make a fade screen that displays over(overlaps) the previous activity and the fade screen also contains the progress bar?


Ther is no need to care about overlapping. Progress Bar is always shown in foreground overlapping the activity containg it.

    import android.app.Activity;
    import android.app.Dialog;
    import android.app.ProgressDialog;
    import android.os.AsyncTask;
    import android.os.Bundle;

    public class ProgressDialogDemo extends Activity {
/** Called when the activity is first created. */
ProgressDialog  dialog;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    dialog = new ProgressDialog(this);
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setMessage("Loading...");
    dialog.setCancelable(true);



    new Loader().execute();


}

class Loader extends AsyncTask<Object, Object, Object> {

    @Override
    protected Object doInBackground(Object... params) {
        // TODO Auto-generated method stub
        for( int i = 0; i <= 100; i++){

            publishProgress( i );
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return null;
    }

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub

        super.onPreExecute();
        dialog.show();
    }

    @Override
    protected void onPostExecute(Object result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        dialog.dismiss();
    }

    @Override
    protected void onProgressUpdate(Object... values) {
        // TODO Auto-generated method stub
        super.onProgressUpdate(values);
        dialog.setProgress( ( (Integer)values[0]).intValue() );
    }

}}
0

精彩评论

暂无评论...
验证码 换一张
取 消