[Android] 自定义Indeterminate ProgressBar颜色

来源:互联网 发布:java proxy 编辑:程序博客网 时间:2024/05/08 23:44

Indeterminate ProgressBar默认是白色的,如果容器的背景也是白色的,这样就根本看不到Progressbar.

简单解决方案:

用style属性设定反转的颜色.

view source
print?
01<ProgressBarstyle="@android:style/Widget.ProgressBar.Inverse"/>
02<ProgressBarstyle="@android:style/Widget.ProgressBar.Large.Inverse"/>
03<ProgressBarstyle="@android:style/Widget.ProgressBar.Small.Inverse"/>

转自: How to change android indeterminate ProgressBar color

高级方案: 自定义颜色

步骤:

  • 用任何图片编辑器编辑一张ProgressBar需要的图片
  • 用这张图片创建一个animation drawable
view source
print?
01<?xmlversion="1.0"encoding="utf-8"?>
02<animated-rotatexmlns:android="http://schemas.android.com/apk/res/android"
03android:drawable="@drawable/image_for_rotation"
04android:pivotX="50%"
05android:pivotY="50%"/>

          @drawable/image_for_rotation 就是那张做好的图片

  • 给ProgressBar widget设定android:indeterminateDrawable
view source
print?
01<?xmlversion="1.0"encoding="utf-8"?>
02<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
03android:orientation="vertical"
04android:layout_width="fill_parent"
05android:layout_height="fill_parent"
06android:gravity="center">
07<ProgressBar
08android:indeterminateDrawable="@drawable/my_progress_indeterminate"
09android:layout_height="100dp"android:layout_width="100dp"/>
10</LinearLayout>
出处:http://www.tedz.me/android/custom-indeterminate-progressbar-color/
原创粉丝点击