首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义进度条Android

自定义进度条Android
EN

Stack Overflow用户
提问于 2012-07-04 13:09:46
回答 2查看 39.8K关注 0票数 9

我想在android中使用这种类型的进度条。我已经尝试了许多水平进度条。它们看起来都像具有不同颜色的默认进度条。不知道如何使用此类型:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-07-04 13:12:46

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

票数 11
EN

Stack Overflow用户

发布于 2013-06-03 20:17:09

自定义进度条需要定义进度条的背景和进度的属性。

在res-> drawable文件夹中创建名为customprogressbar.xml的a.xml文件

customprogressbar.xml

代码语言:javascript
复制
   <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中,请执行以下操作

代码语言:javascript
复制
   <ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:progressDrawable="@drawable/custom_progressbar"         
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

在运行时执行以下

代码语言:javascript
复制
      // Get the Drawable custom_progressbar                     
                              Drawable draw= res.getDrawable(R.drawable.custom_progressbar);
                              // set the drawable as progress drawavle

                              progressBar.setProgressDrawable(draw);
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11322740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档