brian
brian

Reputation: 6922

ProgressDialog style

I show ProgressDialog in AsyncTask method. My code as below:

@Override
protected void onPreExecute() {
super.onPreExecute();
progDailog = new ProgressDialog(MyActivity.this.getParent());
progDailog.setIndeterminate(false);
progDailog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progDailog.setCancelable(true);
progDailog.show();
}

The dialog showed has a long space at right. But I want to show only the left cycle image without the right space. How to modify it?

Upvotes: 2

Views: 10672

Answers (5)

Michele
Michele

Reputation: 2336

I resolve with this code:

ProgressBar pbar = new ProgressBar(this);
pbar.setBackgroundColor(getResources().getColor(android.R.color.white));
int padding = getResources().getDimensionPixelOffset(R.dimen.dialog_default_padding);
pbar.setPadding(padding, padding, padding, padding);
Dialog = progress = new Dialog(this);
progress.requestWindowFeature(Window.FEATURE_NO_TITLE);
progress.setContentView(pbar);
progress.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
progress.show();

Upvotes: 0

Nishant
Nishant

Reputation: 93

Try using ProgressBar and adding it to LinearLayout as follows. In my Case it worked.

ProgressBar mSpinner = new ProgressBar(this);
mSpinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
mSpinner.setBackgroundResource(R.drawable.loading_1);
mSpinner.setIndeterminate(true);
lyt.addView(mSpinner);

enter image description here

Upvotes: 2

Jon Zangitu
Jon Zangitu

Reputation: 967

Note that is not an empty space at the right of the spinner, is a text but the black background doesn't let you see it. I noticed it when I tested in my phone, and I was seeing the message of the ProgressDialog.

enter image description here

You can see the text just right of the spinner. I can't make the text white.

Upvotes: 1

Pradeep Sharma
Pradeep Sharma

Reputation: 35

you can set progress Dialog layout width and height using this code.

 public void onCreate(Bundle savedInstanceState) {   
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    }
    @Override
       protected void onPreExecute() {
    super.onPreExecute();
    progDailog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    }

Upvotes: 1

Thommy
Thommy

Reputation: 5417

The space on the right is because normally there is also a Text to the right of the spinner. If you just want to show the spinner try it with AlertDialog:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
ProgressBar pbar = new ProgressBar(this);
builder.setView(pbar);
builder.create().show();

Upvotes: 5

Related Questions