So richten Thema für indeterministischen ProgressBar in ProgressDialog in Android
-
09-10-2019 - |
Frage
Ich habe ein Android (entwickelt auf A2.2) App mit folgenden Themen definiert:
<style name="ProgressBar"> parent="@android:style/Widget.ProgressBar">
<item name="android:indeterminateDrawable">@drawable/progress_medium</item>
</style>
<style name="AlertDialog" parent="@android:style/AlertDialog">
<item name="android:fullDark">@drawable/bgr_alert</item>
</style>
<style name="MyTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:alertDialogStyle">@style/AlertDialog</item>
<item name="android:progressBarStyle">@style/ProgressBar</item>
</style>
Dabei steht 'progress_medium' ziehbar ist meine Gewohnheit (blau) progressbar und 'bgr_alert' ist custom (weiß) Hintergrund.
Wenn ich den Dialog zeigen (Anwendung ist das Thema 'MyTheme')
@Override
protected Dialog onCreateDialog(int id) {
progressDialog = new ProgressDialog(this);
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
return progressDialog;
}
Der Dialog, der zeigt, enthält bis benutzerdefinierten Hintergrund (weiß), aber die indeterministischen progressBar ist nicht sichtbar.
Auf der anderen Seite, wenn ich den Fortschritt ziehbar manuell:
progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress_medium));
alles perfekt -. Benutzerdefinierten Hintergrund und individuelle Fortschritt ziehbar
Jeder Hinweis, warum der progressBar ziehbar nicht implizit durch Thema Thema eingestellt ist?
Lösung
Ok, I've got my answer. The problem is that Android's progress_dialog.xml layout contains explicit style for ProgressBar:
<ProgressBar android:id="@android:id/progress"
style="@android:style/Widget.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="10000"
android:layout_marginRight="12dip" />
So I have to either do the manual setting (as described above) or do completely custom dialog.
Andere Tipps
I had this problem and was really hard to find the solution.
I think your are using, in your definition of MyTheme android:background:
<style name="MyTheme">
<item name="android:background">@color/white_color</item>
.....
<item name=".....">value</item>
</style>
I've made the same mistake, we should use android:windowBackground and give it a color or a drawable. This way the dialogs will not be affected by your theme background.
Let me know if this solution works for you!