編輯:關於 Android 程式設計
本文將透過實例,說明如何以程式實作自訂的 ProgressBar 樣式,涵蓋背景色、一級進度條與二級進度條的顏色設定,分享給大家參考。
效果圖如下,本例中同時設定了一級進度條與二級進度條:

樣式資源 progressbar_bg.xml,放在 drawable 資料夾下:
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="https://schemas.android.com/apk/res/android"> <!--3個層的順序即為顯示時的疊加順序--> <!--背景色--> <item android:id="@android:id/background"> <shape> <corners android:radius="5dip" /> <solid android:color="#CCCCCC" /> </shape> </item> <!--二級進度條的顏色--> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <corners android:radius="5dip" /> <solid android:color="#88F56100" /> </shape> </clip> </item> <!--一級進度條的顏色,也可以直接替換成圖片--> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="5dip" /> <solid android:color="#F56100" /> </shape> </clip> </item> </layer-list>
版面程式碼如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="https://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ProgressBar android:id="@+id/progress_bar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="100dp" android:minHeight="20dp" android:padding="10dp" android:progressDrawable="@drawable/progressbar_bg" /> </LinearLayout>
透過 layer-list,我們可以將背景、二級進度與一級進度分層堆疊,各自設定不同的顏色與圓角,輕鬆打造出自訂外觀的進度條。二級進度條之所以採用半透明的顏色(如 #88F56100),正是為了讓它與一級進度條疊放時呈現出視覺上的區隔。
希望本文所述的做法,能對大家的 Android 設計有所幫助。
告別制式圖標!手機端自訂APP圖標教學
想自訂APP圖標,需Root後用RE檔案管理器、X-plore與Photoshop手機版。先從APK的res/drawable-hdpi取出icon.png,編輯後存成P
Android TV 開發總結(二):打造 TV Metro 風格介面
前言:上一篇介紹了建構 TV app 前要知道的一些事情。開發 Android TV 與手機本質上沒有太大差別,螢幕大、焦點處理與按鍵處理是它有別於手機和平板的實質差異。
Android 常用調試手段彙總(含 Kernel 調試方法)
除了大家耳熟能詳的 kernel printk、Android 的 DDMS 與 logcat 之外,Android 平台上其實還有不少好用的調試利器。本文重點介紹 bu
動手打造 SwipeBackLayout:一步步實現 Android 右滑退出 Activity
SwipeBackLayout 是什麼GitHub 上早有成熟的手滑返回開源庫,我也日常在用。但身為一個喜歡刨根問底的開發者,我總好奇它背後的實現原理。很多高水平作者寫的