自定义进度条 Android

10

我想在安卓中使用这种类型的进度条。我已经尝试了许多水平进度条,但它们看起来都像是默认进度条,只是颜色不同。不知道如何使用这种类型:输入图像描述


74
在我开始阅读你的问题之前,我实际上坐在这里等待其余部分的内容加载。我想现在是休息时间了。 - snapfractalpop
1
StackOverflow花费时间加载了吗?第一次发生! - Apurva
2个回答

11
你需要创建自己的定制进度条。它不像使用许多水平条那么简单。

5
定制进度条需要定义进度条背景和进度的属性或属性。请在您的res->drawable文件夹中创建一个名为customprogressbar.xml的a.xml文件。
customprogressbar.xml:
   <layer-list xmlns:android="http://schemas.android.com/apk/res/android">

        <!-- Define the background properties like color etc -->
    <item android:id="@android:id/background">
    <shape>
        <gradient
                android:startColor="#000001"
                android:centerColor="#0b131e"
                android:centerY="1.0"
                android:endColor="#0d1522"
                android:angle="270"
        />
    </shape>
   </item>

  <!-- Define the progress properties like start color, end color etc -->
  <item android:id="@android:id/progress">
    <clip>
        <shape>
            <gradient
                android:startColor="#007A00"
                android:centerColor="#007A00"
                android:centerY="1.0"
                android:endColor="#06101d"
                android:angle="270"
            />
        </shape>
    </clip>
</item>

现在你需要将progressDrawable属性设置为customprogressbar.xml(drawable)

你可以在xml文件中或在Activity中(运行时)进行设置

在你的xml文件中,按照以下方式进行设置

   <ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:progressDrawable="@drawable/custom_progressbar"         
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

在运行时执行以下操作。
      // Get the Drawable custom_progressbar                     
                              Drawable draw= res.getDrawable(R.drawable.custom_progressbar);
                              // set the drawable as progress drawavle

                              progressBar.setProgressDrawable(draw);

有没有办法设置旋转的持续时间(速度)? - surlac

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