I have an Android (developed on A2.2) app with following theme defined:
<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>
where 'progress_medium' drawable is my custom (blue) progressbar and 'bgr_alert' is custom (white) bac开发者_JAVA技巧kground.
When I show the dialog (application's theme is 'MyTheme')
@Override
protected Dialog onCreateDialog(int id) {
progressDialog = new ProgressDialog(this);
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
return progressDialog;
}
the dialog that shows up contains custom background (white), but the indeterministic progressBar is not visible.
On the other hand, if I set the progress drawable manually:
progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress_medium));
everything is perfect - custom background and custom progress drawable.
Any hint, why the progressBar drawable is not set implicitly by theme theme?
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.
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!
精彩评论