How to change default color of progress bar?

后端 未结 14 1886
粉色の甜心
粉色の甜心 2020-12-02 15:53

I am using a circular ProgressBar in my Activty.My Problem is this it is not visible properly on my page because my page\'s BG color is same as ProgressBar .So

相关标签:
14条回答
  • 2020-12-02 16:07

    The Chirag's answer is right, but not all.
    I think the XML file should look like this:

    <ProgressBar
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:indeterminateDrawable="@drawable/progress"/>
    
    0 讨论(0)
  • 2020-12-02 16:09

    The easiest way is to use android:indeterminateTint attribute:

    <ProgressBar
            android:indeterminate="true"
            android:indeterminateTint="@android:color/black"
            ........... />
    
    0 讨论(0)
  • 2020-12-02 16:11

    You can also change the color of your progressbar programmatically in your activities oncreate or your fragments onViewCreated()

    pBar.getIndeterminateDrawable().setColorFilter(0xFFFF0000, android.graphics.PorterDuff.Mode.MULTIPLY);
    

    Here the color applied is "0xFFFF0000" which is red. You can change it according to your needs

    0 讨论(0)
  • 2020-12-02 16:13

    Try using this in your XML

    android:indeterminateDrawable="@drawable/yourxmlfile"
    
    style="@android:style/Widget.ProgressBar.Small"
    
    0 讨论(0)
  • 2020-12-02 16:14

    This is an old question, but using theme is not mentioned here. If your default theme is using AppCompat, your ProgressBar's color will be colorAccent you have defined.

    Changing colorAccent will also change your ProgressBar's color, but these changes also reflects at multiple places. So, if you want a different color just for a specific ProgressBar you can do that by applying theme to that ProgressBar alone:

    • Extend your default theme and override colorAccent

      <style name="AppTheme.WhiteAccent">
          <item name="colorAccent">@color/white</item> <!-- Whatever color you want-->
      </style>
      
    • And in ProgressBar add the android:theme attribute:

      android:theme="@style/AppTheme.WhiteAccent"
      

    So it will look something like this:

    <ProgressBar
            android:id="@+id/loading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:padding="10dp"
            android:theme="@style/AppTheme.WhiteAccent" />
    

    So you are just changing a colorAccent for your particular ProgressBar.

    Note: Using style will not work. You need to use android:theme only. You can find more use of theme here: https://plus.google.com/u/0/+AndroidDevelopers/posts/JXHKyhsWHAH

    Edit

    Here is the code for changing the color of ProgressBar by programatically.

    ProgressBar progressBar = (ProgressBar) findViewById(R.id.pb_listProgressBar);
    int colorCodeDark = Color.parseColor("#F44336");
    progressBar.setIndeterminateTintList(ColorStateList.valueOf(colorCodeDark));
    
    0 讨论(0)
  • 2020-12-02 16:14

    in xml u can apply color like this

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/loader"
        android:indeterminateTint="@color/my_color"
        android:layout_centerInParent="true"/>
    
    0 讨论(0)
提交回复
热议问题