1. 程式人生 > >android之修改系統自帶ProgressDialog樣式

android之修改系統自帶ProgressDialog樣式

1.ProgressDialog預設樣式是當前Activity的theme所定義的ProgressDialog樣式。

  繼承自父類AlertDialog的style.

AlertDialog的原始碼

     static int resolveDialogTheme(Context context, int resid) {
        if (resid == THEME_TRADITIONAL) {
            return com.android.internal.R.style.Theme_Dialog_Alert;
        } else if (resid == THEME_HOLO_DARK) {
            return com.android.internal.R.style.Theme_Holo_Dialog_Alert;
        } else if (resid == THEME_HOLO_LIGHT) {
            return com.android.internal.R.style.Theme_Holo_Light_Dialog_Alert;
        } else if (resid == THEME_DEVICE_DEFAULT_DARK) {
            return com.android.internal.R.style.Theme_DeviceDefault_Dialog_Alert;
        } else if (resid == THEME_DEVICE_DEFAULT_LIGHT) {
            return com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog_Alert;
        } else if (resid >= 0x01000000) {   // start of real resource IDs.
            return resid;
        } else {
            TypedValue outValue = new TypedValue();
            context.getTheme().resolveAttribute(com.android.internal.R.attr.alertDialogTheme,
                    outValue, true);
            return outValue.resourceId;
        }
    }

         2.引用系統的樣式,引用不到com.android.internal.R.style.Theme_Holo_Dialog_Alert,而是通過ProgressDialog.THEME_HOLO_LIGHT來引用系統自定義ProgressDialog樣式。

ProgressDialog dialog = new ProgressDialog(this, ProgressDialog.THEME_HOLO_LIGHT);
dialog.setTitle("登入");
dialog.setMessage("正在登入,請稍後...");
//dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(true);
dialog.show();

       3.引用自定義ProgressDialog樣式

轉自http://www.2cto.com/kf/201309/241455.html

轉自http://blog.csdn.net/rohsuton/article/details/7518031

轉自http://blog.csdn.net/luhuajcdd/article/details/8986212

        轉自http://blog.csdn.net/qjlhlh/article/details/7979179