my_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" android:drawable="@drawable/alert_dialog_icon" /> <item android:id="@android:id/progress" android:drawable="@drawable/sun" /> </layer-list>xml layout 布局文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_progress_bar" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="shortcut.song.com.myapplication.ProgressBarActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <!-- 大环形 进度条 --> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" style="@android:style/Widget.ProgressBar.Large" /> <!-- 中环形 进度条 --> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" /> <!-- 小环形 进度条 --> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" style="@android:style/Widget.ProgressBar.Small" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <!-- 水平 进度条 --> <ProgressBar android:id="@+id/progressbar1" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" style="@android:style/Widget.ProgressBar.Horizontal" /> <!-- 自定义轨道的水平 进度条 --> <ProgressBar android:id="@+id/progressbar2" android:layout_width="match_parent" android:layout_height="wrap_content" android:max="100" android:progressDrawable="@drawable/my_progressbar" style="@android:style/Widget.ProgressBar.Horizontal" /> </LinearLayout> </LinearLayout>