ProgressBar样式的定义

网上收集的文章:http://www.bkjia.com/Androidjc/889841.html

1.改变Progress可以通过改写样式的方式,首先看Android自己的进度条样式

这里写图片描述

样式中的参数介绍

<style name="Widget.ProgressBar.Horizontal">
        <item name="android:indeterminateOnly">false</item>
        <item name="android:progressDrawable">@android:drawable/progress_horizontal</item>
        <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
        <item name="android:minHeight">20dip</item>
        <item name="android:maxHeight">20dip</item>
    </style>

android:max=”100”         进度条的最大值
android:progress           进度条已经完成的进度值
android:progressDrawable      已经完成的进度条轨道显示的Drawable对象

indeterminateDrawable      设置绘制不显示进度的进度条的Drawable对象
android:indeterminate        设置为true,进度条不精准显示进度
android:indeterminateDuration   设置不精准显示进度的时间

下面来看资源文件@android:drawable/progress_horizontal

background对应进度条灰色的部分,既背景
secondaryProgress:进度条缓冲时,灰色的部分,图片中没有
progress:对应进度条的样子

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#ff9d9e9d"
                    android:centerColor="#ff5a5d5a"
                    android:centerY="0.75"
                    android:endColor="#ff747674"
                    android:angle="270"
            />
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#80ffd300"
                        android:centerColor="#80ffb600"
                        android:centerY="0.75"
                        android:endColor="#a0ffcb00"
                        android:angle="270"
                />
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#ffffd300"
                        android:centerColor="#ffffb600"
                        android:centerY="0.75"
                        android:endColor="#ffffcb00"
                        android:angle="270"
                />
            </shape>
        </clip>
    </item>
</layer-list>

所以如果想改变一个进度条的样式,可以通过自定义一个drawable文件,重写里面的drawable资源

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@android:id/background"
        android:drawable="@drawable/security_progress_bg"/>
    <item  android:id="@android:id/progress"     android:drawable="@drawable/security_progress"/>
</layer-list>

并且在新的资源上引用到你的样式中

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@android:id/background"
        android:drawable="@drawable/security_progress_bg"/>
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/security_progress"/>
</layer-list>

给你的progressbar引用新的样式

<ProgressBar
                android:id="@+id/progressBar1"
                style="@style/my_pb_style"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp" />
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值