Display progressdialog without text Android
you can add below style in your style.xml
<style name="progress_bar_style">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowTitleStyle">@null</item>
<item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">@android:color/transparent</item>
</style>
where you add any color in color.xml file.
Working and looking good on material design with accent color (if you have them)
Tried hard to make it work on both 5.0+ and lower API version. And the solution is to make it with a dialog instead of a progress.
in layout folder create a file aux_progress_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:gravity="center"
android:orientation="vertical" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent"
/>
</LinearLayout>
Create a function somewhere...let's say Utils.class
public static Dialog LoadingSpinner(Context mContext){
Dialog pd = new Dialog(mContext, android.R.style.Theme_Black);
View view = LayoutInflater.from(mContext).inflate(R.layout.aux_progress_spinner, null);
pd.requestWindowFeature(Window.FEATURE_NO_TITLE);
pd.getWindow().setBackgroundDrawableResource(R.color.transparent);
pd.setContentView(view);
return pd;
}
In your fragment/activity call:
private Dialog progress_spinner;
progress_spinner = Utils.LoadingSpinner(mContext);
//------ Where you want it ------
progress_spinner.show();
//------- Dismiss it --------
progress_spinner.dismiss();
Optional: add a simple CountDownTimer to test how it looks
new CountDownTimer(1000,1000){
@Override public void onTick(long millisUntilFinished) {
}
@Override public void onFinish() {
progress.dismiss();
}
}.start();
If you happen to get the error : "requestFeature() must be called before adding content
", the solution is to call progressDialog.show()
BEFORE you call progressDialog.setContentView(R.layout.progressdialog)
.
Try this 1.create a method like this :
public static ProgressDialog createProgressDialog(Context context) {
ProgressDialog dialog = new ProgressDialog(context);
try {
dialog.show();
} catch (BadTokenException e) {
}
dialog.setCancelable(false);
dialog.getWindow()
.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.progressdialog);
// dialog.setMessage(Message);
return dialog;
}
// Xml Layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent" >
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
and call this method wherever you want :
if (progressDialog == null) {
progressDialog = Utils.createProgressDialog(Login.this);
progressDialog.show();
} else {
progressDialog.show();
}