Nguyễn Nam Hùng Nguyễn Nam Hùng - 12 days ago 7
Android Question

Change circle icon in Dialog

I have a dialog with this code:

progressDialog = new ProgressDialog(this);

//-------------------------------------

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.custom_progress_background, getTheme()));
}
else{
progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.custom_progress_background));
}

//-------------------------------------
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setMessage(getString(R.string.MSG_SEARCH_DOING));
progressDialog.setCancelable(false);
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel_msg), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
isStop = true;
isCancel = true;
showWaitingDialog();
}
});
progressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {

}
});
progressDialog.show();


and have output:
Output dialog

but I want my spinner like this:

Required dialog
anybody can help me do this without use third lib?

Answer

use this line of code to change the progress icon if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { progressDialog.setIndeterminateDrawable(getResources.getDrawable(R.drawable.custom_progress_drawable,getTheme())); }else{ progressDialog.setIndeterminateDrawable(getResources.getDrawable(R.drawable.custom_progress_drawable)); } you will need atleast 4 images to make this custom_progress_drawable.xml, it can be created as under:

<animation-list>
<item android:drawable="@drawable/image1" android:duration="100" />
<item android:drawable="@drawable/image2" android:duration="100" />
<item android:drawable="@drawable/image3" android:duration="100" />
<item android:drawable="@drawable/image4" android:duration="100" /></animation-list>

now set this drawable as your intermediate drawable in the progress dialog