如何在Android中的ProgressDialog中为不确定的ProgressBar设置主题

Pav*_*l P 4 android themes progressdialog customdialog progress-bar

我有一个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>
Run Code Online (Sandbox Code Playgroud)

'progress_medium'drawable是我的自定义(蓝色)进度条,'bgr_alert'是自定义(白色)背景.

当我显示对话框时(应用程序的主题是'MyTheme')

@Override
protected Dialog onCreateDialog(int id) {
  progressDialog = new ProgressDialog(this);
  progressDialog.setCancelable(false);
  progressDialog.setIndeterminate(true);
  return progressDialog;
}
Run Code Online (Sandbox Code Playgroud)

显示的对话框包含自定义背景(白色),但不确定的progressBar不可见.

另一方面,如果我手动设置可绘制的进度:

progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress_medium));
Run Code Online (Sandbox Code Playgroud)

一切都很完美 - 自定义背景和自定义进度可绘制.

任何提示,为什么progressBar drawable不是由主题主题隐式设置的?

Pav*_*l P 14

好的,我有答案.问题是Android的progress_dialog.xml布局包含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" />
Run Code Online (Sandbox Code Playgroud)

因此,我必须进行手动设置(如上所述)或完全自定义对话框.