我一直在尝试改变progressBar的颜色,我注意到它正在使用accentColor(在我的情况下是蓝色),我一直试图改变它而没有运气。
我错过了什么吗?
这是我的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>
这是我在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"/>
我的活动:
public class MainActivity extends android.support.v7.app.AppCompatActivity
答案 0 :(得分:2)
如果要更改某个特定视图的重音颜色,则需要创建样式自己的样式,并使用android:theme
属性将其设置为视图。
已更新
<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"/>
答案 1 :(得分:0)
由于您拥有colorAccent
颜色,因此您需要更改ProgressBar
的颜色:
android:progressBackgroundTint="#a31212" // your color
正如the doc所说:
应用于进度指示器背景的色调。
最后:
<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" />
答案 2 :(得分:0)
试试这个
progressBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.ColorPrimaryDark), Mode.SRC_IN);