安卓学习之—自定义ProgressBar的样式

自定义ProgressBar的样式

查看系统源码(style)可得出,ProgressBar自带样式不符合要求,需要自定义progressDrawable(系统的ProgressBar样式文件中的一个属性)

 

布局文件如下:

<ProgressBar         style="@android:style/Widget.ProgressBar.Horizontal"     android:progressDrawable="@drawable/progress_horizontal_test"

android:layout_width="match_parent"

android:layout_height="wrap_content" />

 

progressDrawable的样式(根据源码的样式)

drawable目录下,新建progress_horizontal_testxml文件

文件如下:

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>

            <solid android:color="#DEDFDE"/>

        shape>

   item>

    

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

        <clip>

            <shape>

                <solid android:color="#5500ae9d"/>

            shape>

        clip>

   item>

    

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

        <clip>

            <shape>

                <solid android:color="#00ae9d"/>

            shape>

        clip>

   item>

layer-list>

 

你可能感兴趣的:(android)