2017-04-04 125 views
1

我正在與紡紗廠合作,並希望將窗口的背景顏色從黑色變爲白色。 下面是進度對話框代碼:如何更改進度對話框的背景顏色?

 if (countProgress > 0) { 
     countProgress += 1; 
     return; 
    } 
    final ProgressDialog progressDialog = new ProgressDialog(activity, DialogFragment.STYLE_NO_TITLE); 
    progressDialog.setIndeterminateDrawable(activity.getResources().getDrawable(R.drawable.progress)); 
    progressDialog.setMessage(msg); 
    progressDialog.setCancelable(false); 
    progressDialog.setCanceledOnTouchOutside(false); 
    stackProgressDialog.push(progressDialog); 
    countProgress = 1; 
    activity.runOnUiThread(new Runnable() { 
     @Override 
     public void run() { 
      progressDialog.show(); 

     } 
    }); 

,這裏是被拉伸的xml:

<?xml version="1.0" encoding="utf-8"?> 
rotate xmlns:android="http://schemas.android.com/apk/res/android" 
android:drawable="@drawable/logo_only_64dp" 
android:pivotX="50%" 
android:pivotY="50%" 
android:fromDegrees="0" 
android:toDegrees="360" 
android:repeatCount="infinite"/> 

回答

1

第1步:定義從Theme.Dialog繼承一個主題:

<style name="MyTheme" parent="@android:style/Theme.Dialog"> 
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item> 
    <item name="android:textColorPrimary">#000000</item> 
</style> 

在那裏,你可以定義整個窗口的背景顏色(問題中的黃色),字體顏色等。真正重要的是android:alertDialogStyle的定義。此樣式控制問題中黑色區域的外觀。

步驟2:定義CustomAlertDialogStyle:

<style name="CustomAlertDialogStyle"> 
    <item name="android:bottomBright">@color/yellow</item> 
    <item name="android:bottomDark">@color/yellow</item> 
    <item name="android:bottomMedium">@color/yellow</item> 
    <item name="android:centerBright">@color/yellow</item> 
    <item name="android:centerDark">@color/yellow</item> 
    <item name="android:centerMedium">@color/yellow</item> 
    <item name="android:fullBright">@color/yellow</item> 
    <item name="android:fullDark">@color/yellow</item> 
    <item name="android:topBright">@color/yellow</item> 
    <item name="android:topDark">@color/yellow</item> 
</style> 

這將設置在問題黃色黑色區域。

步驟3:應用的MyTheme到ProgressDialog,不CustomAlertDialogStyle:

ProgressDialog對話框=新ProgressDialog(此,R.style.MyTheme);

+0

謝謝,這幫助我解決了我的問題! – GAD

+0

不客氣,你能接受答案嗎? –