如何在 Android 中的 ProgressDialog 中为不确定的 ProgressBar 设置主题
我有一个 Android(在 A2.2 上开发)应用程序,定义了以下主题:
<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>
其中“progress_medium”drawable 是我的自定义(蓝色)进度条,“bgr_alert”是自定义(白色)背景。
当我显示对话框(应用程序的主题是“MyTheme”)时,
@Override
protected Dialog onCreateDialog(int id) {
progressDialog = new ProgressDialog(this);
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
return progressDialog;
}
显示的对话框包含自定义背景(白色),但不确定的进度条不可见。
另一方面,如果我手动设置进度可绘制:
progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress_medium));
一切都很完美 - 自定义背景和自定义进度可绘制。
任何提示,为什么 ProgressBar 可绘制对象没有由主题主题隐式设置?
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) background.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我已经得到答案了。问题是Android的progress_dialog.xml布局包含ProgressBar的显式样式:
所以我必须要么进行手动设置(如上所述)要么进行完全自定义的对话框。
Ok, I've got my answer. The problem is that Android's progress_dialog.xml layout contains explicit style for ProgressBar:
So I have to either do the manual setting (as described above) or do completely custom dialog.
我遇到了这个问题,并且很难找到解决方案。
我认为您正在使用 MyTheme android:background 的定义:
我犯了同样的错误,我们应该使用 android:windowBackground 并给它一个颜色或一个可绘制的。这样对话框就不会受到主题背景的影响。
让我知道这个解决方案是否适合您!
I had this problem and was really hard to find the solution.
I think your are using, in your definition of MyTheme android:background:
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!