I've been trying to change the color of the progressBar, and i've noticed it's using the accentColor (which is Blue in my case) and i've been trying to change it without luck.
Am I missing something?
This is in my styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="searchViewStyle">@style/AppTheme.SearchView</item>
<item name="editTextColor">@android:color/white</item>
<item name="actionBarStyle">@style/AppTheme.ActionBarStyle</item>
<item name="actionOverflowButtonStyle">@style/AppTheme.OverFlowItem</item>
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
<item name="colorAccent">@color/ColorPrimaryDark</item>
</style>
This is my element in the layout.xml
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="fill_parent"
style="@style/Widget.AppCompat.ProgressBar"
android:id="@+id/progressBar01"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:indeterminate="true"/>
My activity:
public class MainActivity extends android.support.v7.app.AppCompatActivity
If you want to change accent color for one specific view you need to create style own style and set it to the view using android:theme
attribute.
UPDATED
<style name="CustomProgressBarTheme" parent="Widget.AppCompat.ProgressBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimaryCutom</item>
<item name="colorPrimaryDark">@color/colorPrimaryDarkCustom</item>
<item name="colorAccent">@color/colorAccentCustom</item>
</style>
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="@style/CustomProgressBarTheme"
android:id="@+id/progressBar01"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:indeterminate="true"/>
Since you have colorAccent
with that color, you will need to change the ProgressBar
's color with this:
android:progressBackgroundTint="#a31212" // your color
As the doc says:
Tint to apply to the progress indicator background.
Finally:
<ProgressBar
android:id="@+id/progressBar01"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="120dp"
android:progressBackgroundTint="#a31212" />
试试这个
progressBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.ColorPrimaryDark), Mode.SRC_IN);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.