安卓ProgressBar水平进度条的颜色设置

安卓系统提供了水平进度条ProgressBar的样式,而我们在实际开发中,几乎不可能使用默认的样式,原因就是“太丑”^_^

所以我们在更多的时候需要对其颜色进行自定义,主要使用就是自定义样式文件。

再在drawable目录下新增progressbar.xml文件,可以设置默认背景色和进度条的颜色

(值得一提的是支持渐变色)

代码:

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

    <item android:id="@android:id/background">

        <shape>

            <corners android:radius="5dip" />

            <gradient
                android:angle="0"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:startColor="#ff9d9e9d" />
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">

        <clip>

            <shape>

                <corners android:radius="5dip" />

                <gradient
                    android:angle="0"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:startColor="#80ffd300" />
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">

        <clip>

            <shape>

                <corners android:radius="5dip" />

                <gradient
                    android:angle="0"
                    android:endColor="#8000ff00"
                    android:startColor="#80ff0000" />
            </shape>
        </clip>
    </item>

</layer-list>

布局文件定义如下:

            <ProgressBar
                android:id="@+id/progressBar"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="fill_parent"
                android:layout_height="7.5dp"
                android:max="100"
                android:progress="80"
                android:layout_marginRight="8dp"
                android:progressDrawable="@drawable/progressbar"
                android:visibility="visible"/>
时间: 2024-08-02 19:38:09

安卓ProgressBar水平进度条的颜色设置的相关文章

android progressbar 水平进度条

<?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="@

水平进度条ProgressBar

有些时间没来写了 ,接下来继续分享下本姑娘写的水平进度条,望能帮到初学者~~~ MainActivity 类 package com.lanzx.customprogressbar; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.Menu; import android.view.Men

Android自定义进度条-带文本(文字进度)的水平进度条(ProgressBar)

/** * 带文本提示的进度条 */ public class TextProgressBar extends ProgressBar { private String text; private Paint mPaint; public TextProgressBar(Context context) { super(context); initText(); } public TextProgressBar(Context context, AttributeSet attrs, int d

安卓高级组件-----进度条

进度条组件是安卓重要组件之一.当后台某个程序执行时,前台进度条动态显示了程序执行进度的百分比.是耗时较长的程序让用户觉得在自己的掌控之中,提高程序的友好型. 安卓支支持几种风格的进度条,能通过style属性呢设置进度条风格,该属性如下: @android:style/Widget.ProgressBar.Horizontal    水平进度条 @android:style/Widget.ProgressBar.Inverse        普通环形进度条 @android:style/Widge

ProgressBar 系统进度条【案例】

布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:la

自定义水平进度条样式:黑色虚线

布局layout中使用: 1 <ProgressBar 2 android:id="@+id/progress_bar" 3 style="?android:attr/progressBarStyleHorizontal" <!--必须设置为水平--> 4 android:progressDrawable="@drawable/myprogress" <!--此处用自定义样式--> 5 android:layout_

jQuery Easy UI ProgressBar(进度条)组件

ProgressBar(进度条)组件,这个还是挺好玩的,我们在自己做点什么的时候经常能用到,比如上传下载文件.导入导出文档啊.载入网页等等. 应用场景很多,使用起来还很简单. 示例: <!DOCTYPE html> <html> <head> <title>jQuery Easy UI</title> <meta charset="UTF-8" /> <script type="text/javas

Android简易实战教程--第二十二话《简单的水平进度条》

本打算写一篇自定义水平进度条,但是出于过度和文章的完整性,今天先来一篇简单的进度条. 需求:按钮点击,实现水平进度条加载进度.而且,进度条设置两个进度(到下边的例子里就能知道什么是"第二进度条"了) 配置文件代码如下: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/re

UI控件之ProgressBar(进度条)

(一)概述 (二)常用属性与基础实例 从官方的API我们可以看到这样一个类的关系图: 常用属性详解 : 对应在java我们可以调用下述方法: 先看看系统给我们提供的进度条吧 运行效果如下: 实现代码: xml文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" andro