Reputation: 182
I have a problem to change the color or something of progressDialog. I have seen many examples of change but did not meet my needs, I need your help this is my code:
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_DOWNLOAD_PROGRESS:
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage(getApplicationContext().getString(R.string.download));
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMax(100);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setProgressDrawable(new ColorDrawable(android.graphics.Color.BLUE)); // my bad test
mProgressDialog.setCancelable(true);
mProgressDialog.show();
return mProgressDialog;
default:
return null;
}
}
Upvotes: 1
Views: 1949
Reputation: 5327
A combination of the answer by @VallyN (who gave me the deciding help for this) and more recherche:
mProgressDialog = new ProgressDialog(MainActivity.this) {
@Override
protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ProgressBar bar = (ProgressBar) findViewById(android.R.id.progress);
bar.getProgressDrawable().setColorFilter(0xFF22C819 /*XXX FIXME getColor(R.color.colorAccent)*/, android.graphics.PorterDuff.Mode.SRC_IN);
bar.getIndeterminateDrawable().setColorFilter(0xFF22C819 /*XXX FIXME getColor(R.color.colorAccent)*/, android.graphics.PorterDuff.Mode.SRC_IN);
}
};
This sets the progress bar colour to the desired value independent of whether it’s rendered as indeterminate or 0‥100 (the app in question uses both, first indeterminate until it’s known how much data to download).
The only thing I haven’t yet been able to figure out is how to actually get one of the colours from colors.xml
to be used there, instead of the 0xAARRGGBB
notation. Edits welcome!
Upvotes: 0
Reputation: 320
Hi I think you can create custom progress dialog using Dialog class. You need to setcontentivew of dialog with your custom view.
Try this. https://stackoverflow.com/a/26821095/1554031
Upvotes: 0
Reputation: 1034
Override onCreate
method of ProgressDialog and make any changes you want to its progress bar.
ProgressDialog mProgress = new ProgressDialog(this){
@Override
protected void onCreate(android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Now we retrive this dialog ProgressBar
ProgresBar bar = (ProgressBar) findViewById(android.R.id.progress);
//Do what you want with it here
};
};
Upvotes: 2