自定义进度条

本文介绍了一种使用Android自定义绘制进度条的方法。通过XML定义了进度条的背景形状及不同状态下的颜色变化,实现了圆角矩形背景的水平进度条,并提供了具体的样式配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

drawable 目录:
loding_progress.xml:

<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 设置背景色图像资源 -->
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<corners
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:topLeftRadius="15dp"
android:topRightRadius="15dp" />

<stroke
android:width="15dip"
android:color="#FFFFFF"/>
<gradient
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270" />
</shape>
</item>
<!-- 设置第二级进度条颜色图像资源 -->
<item android:id="@android:id/secondaryProgress" android:drawable="@drawable/go" />
<!-- 设置第一级进度条颜色图像资源 -->
<item android:id="@android:id/progress" android:drawable="@drawable/bg"/>
</layer-list>


不用说了 是shape图形绘画 是进度条的背景

color.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="go">#70000000</drawable>
<drawable name="bg">#0A000000</drawable>
</resources>


main.xml

<ProgressBar
android:id="@+id/LodingBar"
android:progressDrawable="@drawable/loding_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="80dip"
android:layout_marginLeft="100dip"
android:visibility="gone"/>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值