如何在不影响Android边框的情况下仅更改ProgressDialog的背景颜色?

时间:2015-01-22 04:24:02

标签: android android-fragments

我使用以下代码更改Progress Dialog的背景。但是外框的颜色也如下所示。我只想在对话框内进行更改。

<style name="StyledDialog" parent="@android:style/Theme.Panel">
    <item name="android:background">#083044</item>
</style>

enter image description here

根据此问题Change background of ProgressDialog

给出的答案
<style name="StyledDialog" parent="@android:style/Theme.Dialog">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:textColorPrimary">#000000</item>
</style>
<style name="CustomAlertDialogStyle">
    <item name="android:bottomBright">@color/background</item>
    <item name="android:bottomDark">@color/background</item>
    <item name="android:bottomMedium">@color/background</item>
    <item name="android:centerBright">@color/background</item>
    <item name="android:centerDark">@color/background</item>
    <item name="android:centerMedium">@color/background</item>
    <item name="android:fullBright">@color/background</item>
    <item name="android:fullDark">@color/background</item>
    <item name="android:topBright">@color/background</item>
    <item name="android:topDark">@color/background</item>
</style>

此代码可提供完美的背景色。但是,因为对话颜色和活动的背景颜色是相同的。它看起来像透明,没有边框。我和以前一样想要一些边框。

enter image description here

2 个答案:

答案 0 :(得分:5)

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

<style name="StyledDialog" parent="@android:style/Theme.Panel">
    <item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item>
    <item name="android:background">@color/darkblue</item>
</style>

答案 1 :(得分:2)

试试这样。

<style name="StyledDialog" parent="@android:style/Theme.Panel">
    <item name="android:background">@android:color/transparent</item>
    <item name="android:alertDialogStyle">@style/CustomStyle</item>
</style>

<style name="CustomStyle">
    <item name="android:bottomBright">#083044/item>
    <item name="android:bottomDark">#083044</item>
    <item name="android:bottomMedium">#083044</item>
    <item name="android:centerBright">#083044</item>
    <item name="android:centerDark">#083044</item>
    <item name="android:centerMedium">#083044</item>
    <item name="android:fullBright">#083044</item>
    <item name="android:fullDark">#083044</item>
    <item name="android:topBright">#083044</item>
    <item name="android:topDark">#083044</item>
</style>