【问题标题】:Android ProgressDialog styleAndroid ProgressDialog 样式
【发布时间】:2012-04-20 07:36:15
【问题描述】:

如何在 Android 中更改 ProgressDialog 样式?我需要更改背景颜色和文本颜色。

我的应用中有我的一种样式,我必须覆盖哪些项目才能更改进度对话框样式?

我想只使用 xml 来更改样式,而无需编码。有可能吗?

PS:

我没有进度条!我有进度对话框。我想使用样式和主题来改变它的风格,比如我改变了列表视图、窗口背景等的风格。

【问题讨论】:

    标签: android styles themes progressdialog


    【解决方案1】:

    您可以像这样更改 ProgressDialog 的主题:

    ProgressDialog dialog = new ProgressDialog(this, AlertDialog.THEME_HOLO_DARK);
    dialog.setTitle("Title");
    dialog.setMessage("Message");
    dialog.show();
    

    【讨论】:

    • 我想将我的 progressDialog 的颜色更改为橙​​色,我的意思是只更改旋转圆的颜色而不是背景或文本等,您的代码似乎是正确的方法,您能否也给我一个提示xml 文件。非常感谢
    • @m0j1 这个问题有一些很好的答案可以解决:stackoverflow.com/questions/5337613/…
    【解决方案2】:

    自定义对话框的代码: drawable下的文件声明了不同状态的颜色:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:id="@android:id/background">
            <shape>
                <gradient
                        android:startColor="#000001"
                        android:centerColor="#0b131e"
                        android:centerY="0.75"
                        android:endColor="#0d1522"
                        android:angle="270"
                />
            </shape>
        </item>
    
        <item android:id="@android:id/secondaryProgress">
            <clip>
                <shape>
                    <gradient
                            android:startColor="#234"
                            android:centerColor="#234"
                            android:centerY="0.75"
                            android:endColor="#a24"
                            android:angle="270"
                    />
                </shape>
            </clip>
        </item>
    
        <item android:id="@android:id/progress">
            <clip>
                <shape>
                    <gradient
                        android:startColor="#144281"
                        android:centerColor="#0b1f3c"
                        android:centerY="0.75"
                        android:endColor="#06101d"
                        android:angle="270"
                    />
                </shape>
            </clip>
        </item>
    
    </layer-list>
    

    布局 xml 中的代码:

    <ProgressBar android:id="@+id/progressBar"
        android:progressDrawable="@drawable/progress_bar_states"
        android:layout_width="fill_parent" android:layout_height="8dip" 
        style="?android:attr/progressBarStyleHorizontal" 
        android:indeterminateOnly="false" 
        android:max="100">
    </ProgressBar>
    

    【讨论】:

    • 我没有进度条!我有进度对话框。我想使用样式和主题来改变它的风格,比如我改变了列表视图、窗口背景等的风格。
    猜你喜欢
    • 1970-01-01
    • 2016-07-20
    • 2012-02-23
    • 2015-08-24
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    相关资源
    最近更新 更多