Progress Bar Android

时间:2017-01-20 22:18:09

标签: android android-studio progress-bar android-progressbar

我想在应用首次创建时创建progressBar,然后转到第二个活动但是我在这里可以帮助吗?

public class MainActivity extends AppCompatActivity {

    public static String TAG = MainActivity.class.getCanonicalName();


    private ProgressBar mProgress;
    private int mProgressStatus = 0;

    private Handler mHandler = new Handler();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mProgress = (ProgressBar) findViewById(R.id.progressBar);

        new Thread(new Runnable() {
            public void run() {
                while (mProgressStatus < 100) {
                    mProgressStatus ++;
                    // Update the progress bar
                    mHandler.post(new Runnable() {
                        public void run() {
                            mProgress.setProgress(mProgressStatus);

                            }

                        }
                    });
                }
            }
        }).start();

    }

    private void startPlaces() {
        Intent intent = new Intent(this,secondActivity.class);
        startActivity(intent);
    }
}

第二课:

public class Places extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
    }
}

1 个答案:

答案 0 :(得分:0)

for circular progress bar you can try this
http://www.viralandroid.com/2016/02/creating-circular-progressbar-in-android.html

and for starting the another activity as soon as done with the progress bar
outside the while loop you can call

mProgress.post(new Runnable() {
                public void run() {
    mProgress.setVisibility(View.GONE);
                   startPlaces();

                }

            });