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() );
}
}}
精彩评论