自定义ProgressBar,类似浏览器加载显示进度

比较简单,记录一下,以便于以后复制粘贴用

1、控件原生

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="match_parent"
    android:layout_height="3dp" />

2、重点是XML

Activity

mPageLoadingProgressBar = (ProgressBar) findViewById(R.id.progressBar1);// new
// ProgressBar(getApplicationContext(),
// null,
// android.R.attr.progressBarStyleHorizontal);
mPageLoadingProgressBar.setMax(100);
mPageLoadingProgressBar.setProgressDrawable(this.getResources()
        .getDrawable(R.drawable.color_progressbar));

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>   
        <corners android:radius="3dip" />   
        <gradient android:startColor="#ffedeff2"   
                android:centerColor="#ffedeff2"   
                android:centerY="0.75"   
                android:endColor="#ffedeff2"   
                android:angle="270"   
        />   
    </shape> 
    </item>

    <!-- 设置进度条颜色(蓝色) -->
    <item android:id="@android:id/progress">
        <clip>
        <shape>   
            <corners android:radius="3dip" />   
            <gradient android:startColor="#ff399afb"   
                android:endColor="#ff399afb"   />   
        </shape> 
        </clip>
    </item>

</layer-list>


猜你喜欢

转载自blog.csdn.net/qq_26030147/article/details/79437271