自定义ProgressDialog与Indeterminate Drawable无法正常工作

时间:2013-11-27 12:34:04

标签: android

我有一个自定义ProgressDialog,其中包含一个自定义drawable,调用Async任务的预执行,如下所示

 private ProgressDialog progressDialog = new ProgressDialog(BNMlogin.this);

    @Override
    protected void onPreExecute() {

          progressDialog.setMessage("Authenticating Credentials....");
          progressDialog.setIndeterminate(true); 
          progressDialog.setIndeterminateDrawable(getResources().getDrawable(R.drawable.progress_dialog_icon_drawable_animation));
          progressDialog.show();



                 }

drawable是一个动画列表     

<item android:drawable="@drawable/icon_progress_dialog_drawable_1" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_2" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_3" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_4" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_5" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_6" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_7" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_8" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_9" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_10" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_11" android:duration="150" />
<item android:drawable="@drawable/icon_progress_dialog_drawable_12" android:duration="150" />

崩溃时出现以下错误 ......

11-27 15:30:43.439: E/AndroidRuntime(24834):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-27 15:30:43.439: E/AndroidRuntime(24834):    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
11-27 15:30:43.439: E/AndroidRuntime(24834): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01006a a=-1}
11-27 15:30:43.439: E/AndroidRuntime(24834):    at android.content.res.Resources.loadDrawable(Resources.java:2063)
11-27 15:30:43.439: E/AndroidRuntime(24834):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
11-27 15:30:43.439: E/AndroidRuntime(24834):    at android.view.View.<init>(View.java:3364)
11-27 15:30:43.439: E/AndroidRuntime(24834):    at android.view.View.<init>(View.java:3293)

2 个答案:

答案 0 :(得分:0)

我不知道你为什么特意使用onpreexecute。如果要创建自定义对话框,可以参考此处 https://stackoverflow.com/a/26821095/1554031

答案 1 :(得分:0)

    progressDialog.setIndeterminateDrawable(getDrawable(R.drawable.progress_dialog_icon_drawable_animation));