工具栏android中的进度条颜色?

时间:2015-03-31 05:14:20

标签: android toolbar android-appcompat

我在工具栏中使用进度条,默认情况下加载强调颜色,我想自定义进度条的颜色。我正在使用支持库22.0.0

?xml version="1.0" encoding="utf-8"?>
  <android.support.v7.widget.Toolbar  
 xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_aweseome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:background="?attr/colorPrimary">

<ProgressBar
    android:id="@+id/progress_spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right"
    android:indeterminate="true"

     />

所以我尝试使用setColor过滤器

更改进度条颜色
  progressBar = (ProgressBar) findViewById(R.id.progress_spinner);
    progressBar.getIndeterminateDrawable().setColorFilter(Color.parseColor("#FF104D"),//Pink color
            android.graphics.PorterDuff.Mode.MULTIPLY);
    progressBar.setVisibility(View.VISIBLE);

但是我尝试设置为粉红色,但是输出是另一种不同的颜色。

progressBar.getIndeterminateDrawable().setColorFilter(Color.WHITE,android.graphics.PorterDuff.Mode.MULTIPLY)),

当我设置为白色时,它甚至没有出现......

3 个答案:

答案 0 :(得分:4)

使用:

 <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:indeterminateDrawable="@drawable/progress"
             />

在drawable文件夹中使用create progress.xml:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="720" >

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false" >
        <size
            android:height="86dip"
            android:width="86dip" />

        <gradient
            android:angle="0"
            android:endColor="@color/blue"
            android:startColor="@android:color/transparent"
            android:type="sweep"
            android:useLevel="false" />
    </shape>

</rotate>

enter image description here

答案 1 :(得分:1)

试试这个,

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" >

<shape
    android:innerRadiusRatio="3"
    android:shape="ring"
    android:thicknessRatio="20"
    android:useLevel="false" >
    <size
        android:height="48dp"
        android:width="48dp" />

    <gradient
        android:centerColor="@color/tranparent"
        android:centerY="0.50"
        android:endColor="@color/red"
        android:startColor="@color/tranparent"
        android:type="sweep"
        android:useLevel="false" />
</shape>

答案 2 :(得分:0)

尝试使用PorterDuff.Mode.SRC_IN。它对我有用,至少对SeekBar

相关问题