考虑:
样式.xml
<style name="BlueTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="theme_color">@color/theme_color_blue</item>
</style>
attrs.xml
<attr name="theme_color" format="reference" />
颜色.xml
<color name="theme_color_blue">#ff0071d3</color>
最后是可绘制的progress_bar.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>
<stroke
android:width="2px"
android:color="#ff515151" />
<solid android:color="@color/transparent" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="?attr/theme_color" />
</shape>
</clip>
</item>
</layer-list>
使用进度条可绘制时:
<ProgressBar
android:id="@+id/progressBarStartup"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:progressDrawable="@drawable/progress_bar"
android:visibility="visible" />
我得到一个运行时错误。似乎Android无法获取颜色主题。
06-24 16:35:57.032: E/AndroidRuntime(3493): java.lang.RuntimeException: Unable to start activity ComponentInfo{xxx.xxx.activities.startup.ActivityStartup}: android.view.InflateException: Binary XML file line #33: Error inflating class android.widget.ProgressBar
06-24 16:45:32.265: E/AndroidRuntime(9901): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010000 a=-1}