改变ProgressDialog的样式

14

是否有可能更改进度对话框的ProgressBar样式?如果是,那么我该如何做呢?


你想要什么样的风格?...??? - Dinesh Sharma
这很容易做到,代码可以在https://dev59.com/jnE85IYBdhLWcg3wdDEM找到。 - akkilis
谢谢您的快速回复,我只想用自定义动画替换默认的ProgressBar动画。 - Aram
在发布问题前,你应该试着通过谷歌搜索来了解你所问的内容。看看这些谷歌搜索结果:1. 自定义进度对话框 2. 自定义风格的进度对话框 3. 使用自定义布局创建自定义进度对话框 [4. 创建自定义瘦身进度条](http://sherifandroid.blogspot.in/2011/08/creating-skinny - Praveenkumar
可能是Android中自定义进度对话框?的重复问题。 - Oliver
我的回答: https://dev59.com/2GQn5IYBdhLWcg3wVF7i#21795203 - JeffMeJones
1个回答

5
您可以按照以下方式自定义进度对话框的样式: 创建一个带有圆形环形图案的drawable文件(circular_progress_dialog.xml)。
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="270"
android:toDegrees="270">
<shape
    android:innerRadiusRatio="2.5"
    android:shape="ring"
    android:thickness="2dp"
    android:useLevel="true"><!-- this line fixes the issue for lollipop api 21 -->

    <gradient
        android:angle="0"
        android:endColor="@color/main_background"
        android:startColor="@color/main_orange"
        android:type="sweep"
        android:useLevel="false" />
</shape>
</rotate>

如何为进度条添加样式

 <style name="ProgressBar" parent="@android:style/Widget.ProgressBar">
    <item name="android:layout_centerHorizontal">true</item>
    <item name="android:layout_centerVertical">true</item>
    <item name="android:visibility">gone</item>
    <item name="android:background">@color/transparency_pleca</item>
    <item name="android:indeterminateDrawable">@drawable/circular_progress_dialog</item>
</style>

请注意 "android:indeterminateDrawable" 属性。

您可以创建一个 ProgressDialog 实例,并使用您的样式添加。

// create progressDialog
final ProgressDialog myProgressDialog = new  ProgressDialog(MyActivity.this);
myProgressDialog.setProgressStyle(R.style.ProgressBar)
myProgressDialog.show();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接