【问题标题】:How to change color of circular ProgressDialog without set drawable or change color accent如何在不设置可绘制或更改颜色口音的情况下更改圆形 ProgressDialog 的颜色
【发布时间】:2016-11-01 10:48:12
【问题描述】:

我想创建一个具有自定义颜色的ProgressDialog,但我想保留圆形的原始格式。我也不想更改颜色重音,因为它还会更改其他组件颜色,例如 Switch...

请帮我解决这个问题。

谢谢。

【问题讨论】:

    标签: android android-layout android-studio


    【解决方案1】:

    您可以为此使用自定义drawable。用您的颜色替换colorAccent 和其他颜色。

    <?xml version="1.0" encoding="utf-8"?>
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="1440" >
    
        <shape
            android:innerRadiusRatio="3"
            android:shape="ring"
            android:thicknessRatio="15"
            android:useLevel="false" >
    
            <size
                android:height="75dip"
                android:width="75dip" />
    
            <gradient
                android:angle="0"
                android:endColor="@color/colorAccent"
                android:centerColor="@color/colorAccentCenter"
                android:startColor="@color/colorAccentCenter"
                android:type="sweep"
                android:useLevel="false" />
    
        </shape>
    
    </rotate>
    

    【讨论】:

    • 你好,上面的代码对我有用,但是Java代码有没有办法做到这一点?
    • 让我看看。我建议你从现在开始遵循这个例子。 stackoverflow.com/questions/10951978/…
    • 此解决方案用于ProgressBar 而不是ProgressDialog
    • 我提供的链接是针对 ProgressBar,而不是 ProgressDialog。
    • 关于ProgressDialog的问题
    【解决方案2】:

    您可以在 v21 文件夹下的 style.xml 中编写样式,如下所示:

    <style name="ProgressBar" parent="Base.Widget.AppCompat.ProgressBar"> <item name="android:colorAccent">@color/red</item> </style>

    并像这样使用它

    ProgressDialog myProgressDialog = new ProgressDialog(MyActivity.this); myProgressDialog.setProgressStyle(R.style.ProgressBar) myProgressDialog.show();

    【讨论】:

    • v21以上怎么样?
    • 当你把它放在 v21 文件夹时它也支持上面的 API。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    相关资源
    最近更新 更多