169

Androidで円形のプログレスバーを使用しています。これの色を変えたいです。使ってます

"?android:attr/progressBarStyleLargeInverse" 

スタイル。では、プログレスバーの色を変更する方法。

スタイルをカスタマイズする方法は?さらに、スタイルの定義は何ですか?

4

23 に答える 23

177

API21以降の場合。indeterminateTintプロパティを設定するだけです。好き:

android:indeterminateTint="@android:color/holo_orange_dark"

API 21より前のデバイスをサポートするには:

mProgressSpin.getIndeterminateDrawable()
                .setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN );
于 2016-04-24T21:12:28.200 に答える
171

res / drawableフォルダーに、次のように配置します。

progress.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
      android:pivotX="50%" 
      android:pivotY="50%" 
      android:fromDegrees="0"
      android:toDegrees="360">

    <shape 
        android:shape="ring" 
        android:innerRadiusRatio="3"
        android:thicknessRatio="8" 
        android:useLevel="false">

    <size 
        android:width="76dip" 
        android:height="76dip" />

    <gradient 
        android:type="sweep" 
        android:useLevel="false"
        android:startColor="#447a29" 
        android:endColor="#00ffffff"
        android:angle="0"/>

    </shape>

</rotate> 

設定startColorendColor、選択に従って。

progress.xml次に、それをの背景に設定しProgressBarます。

このような

<ProgressBar
  android:id="@+id/ProgressBar01" 
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:indeterminateDrawable="@drawable/progress"
 />
于 2011-03-17T10:14:13.713 に答える
136

1.最初にリソースの下のドローアブルフォルダにxmlファイルを作成します

「progress.xml」という名前

<?xml version="1.0" encoding="utf-8"?>
<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="8"
        android:useLevel="false" >

    <size
        android:height="76dip"
        android:width="76dip" />

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

    </shape>

</rotate>

2.次に、次のスニペットを使用して進行状況バーを作成します

<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/relativeLayout1"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="20dp"
    android:indeterminate="true"
    android:indeterminateDrawable="@drawable/progress" />
于 2013-07-22T10:55:50.933 に答える
67

このコードを使用して、プログラムで色を変更できます。

ProgressBar v = (ProgressBar) findViewById(R.id.progress);
v.getIndeterminateDrawable().setColorFilter(0xFFcc0000,
                        android.graphics.PorterDuff.Mode.MULTIPLY);

ProgressDialogのプログレスバーの色を変更したい場合は、これを使用できます:

mDilog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            ProgressBar v = (ProgressBar)mDilog.findViewById(android.R.id.progress);
            v.getIndeterminateDrawable().setColorFilter(0xFFcc0000,
                    android.graphics.PorterDuff.Mode.MULTIPLY);

        }
    });
于 2014-02-27T14:54:14.203 に答える
38

Datoの答えに追加すると、SRC_ATOPはアルファチャネルをより適切にサポートするため、乗算するのに適したフィルターであることがわかります。

ProgressBar v = (ProgressBar) findViewById(R.id.progress);
v.getIndeterminateDrawable().setColorFilter(0xFFcc0000, android.graphics.PorterDuff.Mode.SRC_ATOP);
于 2014-09-12T17:42:21.313 に答える
35

android:indeterminateTint = "@ color / progressbar"

于 2017-03-18T16:48:09.077 に答える
18

styles.xml

<style name="CircularProgress" parent="Theme.AppCompat.Light">
    <item name="colorAccent">@color/yellow</item>
</style>

  <ProgressBar
        android:layout_width="@dimen/d_40"
        android:layout_height="@dimen/d_40"
        android:indeterminate="true"
        style="@style/Widget.AppCompat.ProgressBar"
        android:theme="@style/CircularProgress"/>
于 2017-03-08T07:26:39.970 に答える
13

それは私にとってはうまくいきます。

<ProgressBar
android:id="@+id/ProgressBar01" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="@color/black"/>
于 2017-10-16T12:51:38.973 に答える
12

円形のプログレスバーをカスタマイズするには、カスタムプログレスバーを表示するためのindeterminateDrawableを作成する必要があります

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:duration="1">

    <shape
        android:innerRadiusRatio="3"
        android:shape="ring"
        android:thicknessRatio="8"
        android:useLevel="false">

        <size
            android:height="48dip"
            android:width="48dip" />

        <gradient
            android:centerColor="#f96047"
            android:centerY="0.50"
            android:endColor="#fb9c8d"
            android:startColor="#f72d0c"
            android:type="sweep"
            android:useLevel="false" />

    </shape>

</rotate>

以下のように、ドローアブルをプログレスバーに含める必要があります。

<ProgressBar
    android:layout_width="wrap_content"
    android:layout_centerInParent="true"
    style="?android:attr/progressBarStyleLarge"
    android:visibility="visible"
    android:progressDrawable="@drawable/widget_progressbar"
    android:indeterminateDrawable="@drawable/widget_progressbar"
    android:layout_height="wrap_content" />
于 2015-06-23T06:22:51.767 に答える
10

この答えをチェックしてください:

私にとって、これらの2つの線は、それが機能して色を変更するために存在する必要がありました。

android:indeterminateTint="@color/yourColor"
android:indeterminateTintMode="src_in"

PS:しかしそれはアンドロイド21からのみ利用可能です

于 2019-07-08T14:47:10.147 に答える
9

私にとって、テーマはaccentColorで機能していませんでした。しかし、colorControlActivatedでは機能しました

    <style name="Progressbar.White" parent="AppTheme">
        <item name="colorControlActivated">@color/white</item>
    </style>

  <ProgressBar
        android:layout_width="@dimen/d_40"
        android:layout_height="@dimen/d_40"
        android:indeterminate="true"
        android:theme="@style/Progressbar.White"/>
于 2017-08-01T13:51:44.107 に答える
8
<style name="progressColor" parent="Widget.AppCompat.ProgressBar">
    <item name="colorControlActivated">@color/colorPrimary</item>
</style>


<ProgressBar
    android:id="@+id/progressBar"
    android:layout_width="250dp"
    android:theme="@style/progressColor"
    android:layout_height="250dp"
    android:layout_centerInParent="true" />
于 2020-07-19T08:26:14.100 に答える
6

マテリアルコンポーネントライブラリを使用するCircularProgressIndicatorと、次の属性でを使用できます。

  • indicatorColor

  • trackColor

          <com.google.android.material.progressindicator.CircularProgressIndicator
              android:indeterminate="true"
              app:trackColor="@color/..."
              app:indicatorSize="90dp"
              app:indicatorColor="@color/..."
              />
    

ここに画像の説明を入力してください

于 2021-03-23T18:17:37.657 に答える
4

アクティビティテーマにアイテムcolorControlActivatedを追加します。次に例を示します。

    <style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
            ...
            <item name="colorControlActivated">@color/rocket_black</item>
            ...
    </style>

マニフェストのアクティビティにこのスタイルを適用します。

<activity
    android:name=".packege.YourActivity"
    android:theme="@style/AppTheme.NoActionBar"/>
于 2017-08-02T15:00:17.023 に答える
4

Muhamed Riyas Mの投票数の多い回答を補足するには、次のようにします。

より速い回転

android:toDegrees="1080"

より薄いリング

android:thicknessRatio="16"

ライトホワイト

android:endColor="#80ffffff"
于 2018-10-20T02:22:38.477 に答える
4

スタイルを使用して、colorControlActivatedのProgressBarの色を設定してみてください。

<style name="progressColor" parent="Widget.AppCompat.ProgressBar">
    <item name="colorControlActivated">@color/COLOR</item>
</style>

次に、ProgressBarのテーマを新しいスタイルに設定します。

<ProgressBar
    android:id="@+id/progress_bar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:theme="@style/progressColor"
 />
于 2020-02-05T01:32:17.667 に答える
3

以下のように進行状況の色を変更するスタイルを使用できます

 <style name="AppTheme.anyName">
        <item name="colorAccent">YOUR_COLOR</item>
    </style>

以下のようにプログレスバーで使用します

<ProgressBar
            style="?android:attr/progressBarStyle"
            android:theme="@style/AppTheme.WhiteAccent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/dimen_30"
        />

それが役に立てば幸い。

于 2018-09-04T13:59:12.100 に答える
2

他の回答のxmlを再利用して、カスタムダイアログでこれを非常に簡単に行うことができます。

<?xml version="1.0" encoding="utf-8"?>

<shape
    android:innerRadiusRatio="3"
    android:shape="ring"
    android:thicknessRatio="8"
    android:useLevel="false" >

    <size
        android:height="76dip"
        android:width="76dip" />

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

</shape>

これを行うだけです:

public static class ModifiedProgressDialog extends ProgressDialog {
    public ModifiedProgressDialog(Context context) {
        super(context);
    }

    @Override
    public void show() {
        super.show();
        setIndeterminateDrawable(getContext().getResources().getDrawable(R.drawable.blue_progress));
    }
}
于 2016-11-15T18:11:00.457 に答える
1

カスタムプログレスの速度を上げる方法を疑問に思っているすべての人のために

  <?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
android:toDegrees="1080"><!--HERE YOU COULD INCREASE SPEED BY SETTING TODEGRESS(1080 is 3 loops instead of 1 in same amt of time)-->
<shape android:shape="ring" android:innerRadiusRatio="3"
    android:thicknessRatio="8" android:useLevel="false">
    <size android:width="76dip" android:height="76dip" />
    <gradient android:type="sweep" android:useLevel="false"
        android:startColor="#447a29" 
        android:endColor="#447a29"
        android:angle="0"
         />
</shape>

于 2018-02-19T06:55:40.223 に答える
0

Res / Values / Colors.xml-> colorAccentから色の値を取得します。変更すると、progressBarの色も変更されます。

于 2020-01-16T10:47:37.410 に答える
0

セットするandroid:indeterminateDrawable="@drawable/progress_custom_rotate"

カスタム円形リングプログレスバーには以下のコードを使用してください

以下のコードをコピーして、Drawableフォルダーに「progress_custom_rotate.xml」を作成します

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
    android:toDegrees="1080">

    <shape android:shape="ring" android:innerRadiusRatio="3"
        android:thicknessRatio="8" android:useLevel="false">

        <size android:width="48dip" android:height="48dip" />

        <gradient android:type="sweep" android:useLevel="false"
            android:startColor="#4c737373" android:centerColor="#4c737373"
            android:centerY="0.50" android:endColor="#ffffd300" />

    </shape>

</rotate>
于 2020-04-19T21:58:32.890 に答える
0

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/black</item>
        <item name="colorPrimaryDark">@color/white</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="progressColor" parent="Widget.AppCompat.ProgressBar">
        <item name="colorControlActivated">@color/black</item>
    </style>
</resources>
<ProgressBar
            android:id="@+id/progressBar2"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:theme="@style/progressColor"
            app:layout_constraintBottom_toBottomOf="@+id/textView3"
            app:layout_constraintStart_toEndOf="@+id/textView3"
            app:layout_constraintTop_toTopOf="@+id/textView3" />

于 2021-03-08T12:02:46.597 に答える
-1

以下のコードを使用して、プログレスバーの色を変更できます。

progressBar.getProgressDrawable().setColorFilter(
    getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_IN);
于 2016-08-16T07:26:34.223 に答える