Android自訂橫向的ProgressBar

來源:互聯網
上載者:User

標籤:

廢話少說,先看一下效果吧,顏色有點醜,不過準系統都有提到,實際使用中修改一下就ok。

其實很簡單,上代碼!

在res下建立drawable檔案夾,建立檔案drawable/progressbar_color.xml

<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" >    <!-- 背景  gradient是漸層,corners定義的是圓角 -->    <item android:id="@android:id/background">        <shape>            <corners android:radius="10dp" />            <solid android:color="#ffffff" />        </shape>    </item>    <!-- 第二條進度條顏色 -->    <item android:id="@android:id/secondaryProgress">        <clip>            <shape>                <corners android:radius="10dip" />                <gradient                    android:angle="90.0"                    android:centerColor="#ac6079"                    android:centerY="0.45"                    android:endColor="#6c213a"                    android:startColor="#e71a5e" />            </shape>        </clip>    </item>    <!-- 進度條 -->    <item android:id="@android:id/progress">        <clip>            <shape>                <corners android:radius="10dip" />                <solid android:color="#FF8080" />            </shape>        </clip>    </item></layer-list>

然後在布局中引用就可以了。

activity_main.xml

<ProgressBar         android:id="@+id/my_progress"        android:layout_width="match_parent"        android:layout_height="12dp"        android:max="100"        android:progress="40"        android:secondaryProgress="70"        style="?android:attr/progressBarStyleHorizontal"        android:progressDrawable="@drawable/progressbar_color"/>

運行之後就是上面的效果啦。

Android自訂橫向的ProgressBar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.