문제

Android 애플리케이션에서 수평 진행률 표시 줄을 사용하고 있으며 진행률을 변경하고 싶습니다 (기본적으로 노란색). 어떻게 사용할 수 있습니까? code (XML 아님)?

도움이 되었습니까?

해결책

답이 아니라고 죄송합니다. 그러나 요구 사항을 코드에서 설정하는 것은 무엇입니까? 그리고 .setProgressDrawable 올바르게 정의 된 경우 작동해야합니다

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
    <shape>
        <corners android:radius="5dip" />
        <gradient
                android:startColor="#ff9d9e9d"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#80ffd300"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners
                android:radius="5dip" />
            <gradient
                android:startColor="@color/progress_start"
                android:endColor="@color/progress_end"
                android:angle="270" 
            />
        </shape>
    </clip>
</item>

</layer-list>

다른 팁

수평 진행 상황에서는 a를 사용할 수 있습니다 ColorFilter, 다음과 같이 :

progressBar.getProgressDrawable().setColorFilter(
    Color.RED, android.graphics.PorterDuff.Mode.SRC_IN);

Red ProgressBar using color filter

메모: 이것은 앱의 모든 진행률 막대의 모양을 수정합니다. 하나의 특정 진행 막대 만 수정하려면 다음을 수행하십시오.

Drawable progressDrawable = progressBar.getProgressDrawable().mutate();
progressDrawable.setColorFilter(Color.RED, android.graphics.PorterDuff.Mode.SRC_IN);
progressBar.setProgressDrawable(progressDrawable);

ProgressBar가 불확실한 경우 사용하십시오 getIndeterminateDrawable() 대신에 getProgressDrawable().

Lollipop (API 21)이므로 진행 상황을 설정할 수 있습니다.

progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED));

Red ProgressBar using progress tint

이것은 프로그래밍 방식이 아니지만 어쨌든 많은 사람들을 도울 수 있다고 생각합니다.
나는 많은 것을 시도했고 가장 효율적인 방법은 .xml 파일의 진행 상황 에이 줄을 추가하는 것이 었습니다.

            android:indeterminate="true"
            android:indeterminateTintMode="src_atop"
            android:indeterminateTint="@color/secondary"

결국이 코드는 다음을 수행했습니다.

<ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginTop="50dp"
            android:layout_marginBottom="50dp"
            android:visibility="visible"
            android:indeterminate="true"
            android:indeterminateTintMode="src_atop"
            android:indeterminateTint="@color/secondary">

이 솔루션은 API 21+

불확실한 ProgressBar (Spinner)의 경우 드로우 가능에 컬러 필터를 설정했습니다. 훌륭하고 한 줄만 작동합니다.

색상을 빨간색으로 설정하는 예 :

ProgressBar spinner = new android.widget.ProgressBar(
                context,
                null,
                android.R.attr.progressBarStyle);

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

enter image description here

이것은 오래된 질문이지만 테마를 사용하는 것은 여기에 언급되지 않았습니다. 기본 테마가 사용중인 경우 AppCompat, 당신의 ProgressBar색상이 될 것입니다 colorAccent 당신은 정의했습니다.

바꾸다 colorAccent 또한 당신의 변화를 바꿀 것입니다 ProgressBar색상이지만 변화는 여러 곳에서도 반영됩니다. 따라서 특정 색상을 위해 다른 색상을 원한다면 PregressBar 테마를 적용하여 그렇게 할 수 있습니다 ProgressBar :

  • 기본 테마를 확장하고 재정의하십시오 colorAccent

    <style name="AppTheme.WhiteAccent">
        <item name="colorAccent">@color/white</item> <!-- Whatever color you want-->
    </style>
    
  • 그리고에서 ProgressBar 추가 android:theme 기인하다:

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

그래서 그것은 다음과 같이 보일 것입니다.

<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" />

그래서 당신은 방금 a를 바꾸고 있습니다 colorAccent 당신의 특별한 경우 ProgressBar.

메모: 사용 style 작동 안 할 것이다. 사용해야합니다 android:theme 뿐. 여기에서 더 많은 테마 사용을 찾을 수 있습니다. https://plus.google.com/u/0/+androiddevelopers/posts/jxhkyhswhah

모든 API

모든 API를 사용하는 경우 스타일로 테마를 만듭니다.

style.xml

<resources>

    //...

    <style name="progressBarBlue" parent="@style/Theme.AppCompat">
        <item name="colorAccent">@color/blue</item>
    </style>

</resources>

진행중인 사용

<ProgressBar
    ...
    android:theme="@style/progressBarBlue" />

API 레벨 21 이상

API 레벨 21 이상에서 사용되는 경우이 코드를 사용하십시오.

<ProgressBar
   //...
   android:indeterminate="true"
   android:indeterminateTintMode="src_atop"
   android:indeterminateTint="@color/secondary"/>

일부 제안에 따라 색상으로 모양과 클립 도용 가능성을 지정한 다음 설정할 수 있습니다. 이 작업이 프로그래밍 방식으로 작동합니다. 이것이 내가하는 방법입니다 ..

먼저 Drawable Library를 가져 오는지 확인하십시오 ..

import android.graphics.drawable.*;

그런 다음 아래와 유사한 코드를 사용하십시오.

ProgressBar pg = (ProgressBar)row.findViewById(R.id.progress);
final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
pgDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));
String MyColor = "#FF00FF";
pgDrawable.getPaint().setColor(Color.parseColor(MyColor));
ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
pg.setProgressDrawable(progress);   
pg.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));
pg.setProgress(45);

이것은 나를 위해 효과가있었습니다.

<ProgressBar
 android:indeterminateTint="#d60909"
 ... />

불확실한 경우 :

((ProgressBar)findViewById(R.id.progressBar))
    .getIndeterminateDrawable()
    .setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);

요즘 2016 년에 나는 일부 사전 롤리팝 장치가 colorAccent 설정, 모든 API에 대한 최종 솔루션이 다음과 같습니다.

// fixes pre-Lollipop progressBar indeterminateDrawable tinting
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {

    Drawable wrapDrawable = DrawableCompat.wrap(mProgressBar.getIndeterminateDrawable());
    DrawableCompat.setTint(wrapDrawable, ContextCompat.getColor(getContext(), android.R.color.holo_green_light));
    mProgressBar.setIndeterminateDrawable(DrawableCompat.unwrap(wrapDrawable));
} else {
    mProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(getContext(), android.R.color.holo_green_light), PorterDuff.Mode.SRC_IN);
}

보너스 포인트의 경우 더 이상 사용되지 않은 코드를 사용하지 않습니다. 시도 해봐!

이것이 내가 한 일입니다. 일했다.

진행 표시 줄:

<ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="4"
            android:indeterminateDrawable="@drawable/progressdrawable"
           />

ProgressDrawable.xml :
여기서 그라디언트를 사용하여 원하는대로 색상을 변경하십시오. 및 Android : Todegrees = "x"는 x와 ProgressBar의 값이 빠르게 회전합니다. 감소하고 느리게 회전합니다. 필요에 따라 양육하십시오.

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

            <shape
                android:innerRadius="20dp"
                android:shape="ring"
                android:thickness="4dp"
                android:useLevel="false" >
                <size
                    android:height="48dp"
                    android:width="48dp" />

                <gradient
                    android:centerColor="#80ec7e2a"
                    android:centerY="0.5"
                    android:endColor="#ffec7e2a"
                    android:startColor="#00ec7e2a"
                    android:type="sweep"
                    android:useLevel="false" />
            </shape>

        </rotate>

견본: enter image description here

기본 진행률 표시 줄의 모양/느낌을 수정하는 동안 동일한 문제를 겪습니다. 사람들을 도울 수있는 더 많은 정보가 있습니다. :)

  • XML 파일의 이름에는 문자 만 포함되어야합니다. a-z0-9_. (예 : 수도 없음!)
  • 당신의 "drawable"을 참조하기 위해 R.drawable.filename
  • 기본 모양을 무시하려면 사용합니다 myProgressBar.setProgressDrawable(...), 그러나 사용자 정의 레이아웃을 다음과 같이 언급 할 수는 없습니다. R.drawable.filename, 당신은 그것을 a로 검색해야합니다 Drawable:
    Resources res = getResources();
    myProgressBar.setProgressDrawable(res.getDrawable(R.drawable.filename);
    
  • 진행하기 전에 스타일을 설정해야합니다/2 차 진행/최대 (나중에 나를 위해 그것을 설정하면 '빈'진행 막대가 생겼습니다)

이 답변에는 언급되지 않은 것이있을 것입니다.

테마가 상속되는 경우 Theme.AppCompat, ProgressBar 정의한 색상을 가정합니다 "colorAccent" 당신의 테마에서.

그래서, 사용 ..

<item name="colorAccent">@color/custom_color</item>

.. ProgressBar의 색상을 자동으로 @color/custom_color .

수평 진행 상황에서 어떻게했는지 :

    LayerDrawable layerDrawable = (LayerDrawable) progressBar.getProgressDrawable();
    Drawable progressDrawable = layerDrawable.findDrawableByLayerId(android.R.id.progress);
    progressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);

스타일, 테마 또는 Android : IndeterminateTint = "@Color/YourColor"를 원하는 곳에서 변경하려고 시도 할 수 있지만 Android SKD 버전에서 작동하는 한 가지 방법이 있습니다.

진행 막대가 불확실하지 않은 경우 사용하십시오.

progressBar.getProgressDrawable().setColorFilter(ContextCompat.getColor(context, R.color.yourColor), PorterDuff.Mode.SRC_IN );

진행 막대가 불확실한 경우 사용하십시오.

progressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(getContext(), R.color.yourColor), PorterDuff.Mode.SRC_IN );

안드로이드가 너무 엉망이라는 것이 슬프다!

android:progressTint="#ffffff" 

가장 간단한 솔루션 레이아웃 XML 파일에서 색상을 변경하려면 아래 코드를 사용하고 사용하십시오. 불확실한 원하는 색상의 속성.

    <ProgressBar
      android:id="@+id/progressBar"
      style="?android:attr/progressBarStyle"
      android:layout_width="wrap_content"
      android:indeterminate="true"
      android:indeterminateTintMode="src_atop"
      android:indeterminateTint="#ddbd4e"
      android:layout_height="wrap_content"
      android:layout_marginBottom="20dp"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true" />

이 솔루션은 저에게 효과적이었습니다.

<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"/>

한 가지 더 작은 점은 테마 솔루션이 기본 테마를 상속하면 작동하므로 앱의 경우 테마가 다음과 같습니다.

<style name="AppTheme.Custom" parent="@style/Theme.AppCompat">
    <item name="colorAccent">@color/custom</item>
</style>

그런 다음 이것을 진행률 표시 줄 테마로 설정하십시오

<ProgressBar
    android:id="@+id/progressCircle_progressBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:theme="@style/AppTheme.Custom"
    android:indeterminate="true"/>

정보를 추가하기 위해 게시되었습니다 Paulieg의 대답, Ateiob이 나에게 뭔가를 설명 해달라고 부탁 한 이후 ...


나는 현재 버그/문제/최적화가 ProgressBar 진행 상황을 이미 값으로 설정하려는 시도를 무시하는 코드.

  • 즉, Progress = 45 인 경우 45로 설정하려고하면 코드가 아무것도하지 않고 진행 상황을 다시 그리지 않을 것입니다.

전화 후 ProgressBar.setProgressDrawable(), 당신의 진행률 막대는 비워집니다 (드로우 가능한 부분을 변경했기 때문에).

이것은 당신이 진행 상황을 설정하고 그것을 다시 그리는 것을 의미합니다. 그러나 진행 상황을 보존 가치로 설정하면 아무것도하지 않습니다.

먼저 0으로 설정 한 다음 "오래된"값으로 다시 설정해야합니다. 막대가 다시 그리기됩니다.


요약하기 위해 :

  • "오래된"진행 가치를 유지하십시오
  • Drawable / Color 업데이트 (BAR BARK MAKED)
  • 진행 상황을 0으로 재설정하십시오 (그렇지 않으면 다음 줄은 아무것도하지 않습니다)
  • 진행 상황을 "오래된"값으로 재설정하십시오 (수정 막대)
  • 무효

아래는 다음을 수행하는 방법입니다.

protected void onResume()
{
    super.onResume();
    progBar = (ProgressBar) findViewById(R.id.progress_base);

    int oldProgress = progBar.getProgress();

    // define new drawable/colour
    final float[] roundedCorners = new float[]
        { 5, 5, 5, 5, 5, 5, 5, 5 };
    ShapeDrawable shape = new ShapeDrawable(new RoundRectShape(
        roundedCorners, null, null));
    String MyColor = "#FF00FF";
    shape.getPaint().setColor(Color.parseColor(MyColor));
    ClipDrawable clip = new ClipDrawable(shape, Gravity.LEFT,
        ClipDrawable.HORIZONTAL);
    progBar.setProgressDrawable(clip);

    progBar.setBackgroundDrawable(getResources().getDrawable(
        android.R.drawable.progress_horizontal));

    // work around: setProgress() ignores a change to the same value
    progBar.setProgress(0);
    progBar.setProgress(oldProgress);

    progBar.invalidate();
}

HappyEngineer의 솔루션까지는 "진행"오프셋을 수동으로 설정하는 것이 비슷한 해결 방법이라고 생각합니다. 두 경우 모두 위의 코드가 효과가 있어야합니다.

사용 Android.support.v4.graphics.drawable.drawablecompat:

            Drawable progressDrawable = progressBar.getIndeterminateDrawable();
            if (progressDrawable  != null) {
                Drawable mutateDrawable = progressDrawable.mutate();
                DrawableCompat.setTint(mutateDrawable, primaryColor);
                progressBar.setProgressDrawable(mutateDrawable);
            }

수평 스타일의 진행 막대의 경우 다음을 사용합니다.

import android.widget.ProgressBar;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ClipDrawable;
import android.view.Gravity;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;

public void setColours(ProgressBar progressBar,
                        int bgCol1, int bgCol2, 
                        int fg1Col1, int fg1Col2, int value1,
                        int fg2Col1, int fg2Col2, int value2)
  {
    //If solid colours are required for an element, then set
    //that elements Col1 param s the same as its Col2 param
    //(eg fg1Col1 == fg1Col2).

    //fgGradDirection and/or bgGradDirection could be parameters
    //if you require other gradient directions eg LEFT_RIGHT.

    GradientDrawable.Orientation fgGradDirection
        = GradientDrawable.Orientation.TOP_BOTTOM;
    GradientDrawable.Orientation bgGradDirection
        = GradientDrawable.Orientation.TOP_BOTTOM;

    //Background
    GradientDrawable bgGradDrawable = new GradientDrawable(
            bgGradDirection, new int[]{bgCol1, bgCol2});
    bgGradDrawable.setShape(GradientDrawable.RECTANGLE);
    bgGradDrawable.setCornerRadius(5);
    ClipDrawable bgclip = new ClipDrawable(
            bgGradDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);     
    bgclip.setLevel(10000);

    //SecondaryProgress
    GradientDrawable fg2GradDrawable = new GradientDrawable(
            fgGradDirection, new int[]{fg2Col1, fg2Col2});
    fg2GradDrawable.setShape(GradientDrawable.RECTANGLE);
    fg2GradDrawable.setCornerRadius(5);
    ClipDrawable fg2clip = new ClipDrawable(
            fg2GradDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);        

    //Progress
    GradientDrawable fg1GradDrawable = new GradientDrawable(
            fgGradDirection, new int[]{fg1Col1, fg1Col2});
    fg1GradDrawable.setShape(GradientDrawable.RECTANGLE);
    fg1GradDrawable.setCornerRadius(5);
    ClipDrawable fg1clip = new ClipDrawable(
            fg1GradDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);        

    //Setup LayerDrawable and assign to progressBar
    Drawable[] progressDrawables = {bgclip, fg2clip, fg1clip};
    LayerDrawable progressLayerDrawable = new LayerDrawable(progressDrawables);     
    progressLayerDrawable.setId(0, android.R.id.background);
    progressLayerDrawable.setId(1, android.R.id.secondaryProgress);
    progressLayerDrawable.setId(2, android.R.id.progress);

    //Copy the existing ProgressDrawable bounds to the new one.
    Rect bounds = progressBar.getProgressDrawable().getBounds();
    progressBar.setProgressDrawable(progressLayerDrawable);     
    progressBar.getProgressDrawable().setBounds(bounds);

    // setProgress() ignores a change to the same value, so:
    if (value1 == 0)
        progressBar.setProgress(1);
    else
        progressBar.setProgress(0);
    progressBar.setProgress(value1);

    // setSecondaryProgress() ignores a change to the same value, so:
    if (value2 == 0)
        progressBar.setSecondaryProgress(1);
    else
        progressBar.setSecondaryProgress(0);
    progressBar.setSecondaryProgress(value2);

    //now force a redraw
    progressBar.invalidate();
  }

예제 호출은 다음과 같습니다.

  setColours(myProgressBar, 
          0xff303030,   //bgCol1  grey 
          0xff909090,   //bgCol2  lighter grey 
          0xff0000FF,   //fg1Col1 blue 
          0xffFFFFFF,   //fg1Col2 white
          50,           //value1
          0xffFF0000,   //fg2Col1 red 
          0xffFFFFFF,   //fg2Col2 white
          75);          //value2

'2 차 진행'이 필요하지 않은 경우 value2를 value1로 설정하십시오.

이 사용자 지정 스타일을 진행률 표시 줄에 적용하십시오.

<style name="customProgress" parent="@android:style/Widget.ProgressBar.Small">
        <item name="android:indeterminateDrawable">@drawable/progress</item>
        <item name="android:duration">40</item>
        <item name="android:animationCache">true</item>
        <item name="android:drawingCacheQuality">low</item>
        <item name="android:persistentDrawingCache">animation</item>
    </style>

@drawable/progress.xml-

<?xml version="1.0" encoding="utf-8"?>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/spinner_white"
    android:pivotX="50%"
    android:pivotY="50%" />

이 유형의 이미지를 사용하여 진행률 표시 줄에 사용하십시오.enter image description here

더 나은 결과를 얻으려면 여러 진보 이미지를 사용할 수 있습니다. Android 플랫폼 자체는 ProgressBar에 이미지를 사용하기 때문에 이미지 사용을 망설이지 마십시오. 코드는 SDK에서 추출됩니다 :)

프로그래밍 방식으로 진행바의 색상을 변경하기위한 코드는 다음과 같습니다.

ProgressBar progressBar = (ProgressBar) findViewById(R.id.pb_listProgressBar);
int colorCodeDark = Color.parseColor("#F44336");
progressBar.setIndeterminateTintList(ColorStateList.valueOf(colorCodeDark));
ProgressBar freeRamPb = findViewById(R.id.free_ram_progress_bar);

freeRamPb.getProgressDrawable().setColorFilter(
Color.BLUE, android.graphics.PorterDuff.Mode.SRC_IN);
ProgressBar bar;

private Handler progressBarHandler = new Handler();

GradientDrawable progressGradientDrawable = new GradientDrawable(
        GradientDrawable.Orientation.LEFT_RIGHT, new int[]{
                0xff1e90ff,0xff006ab6,0xff367ba8});
ClipDrawable progressClipDrawable = new ClipDrawable(
        progressGradientDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
Drawable[] progressDrawables = {
        new ColorDrawable(0xffffffff),
        progressClipDrawable, progressClipDrawable};
LayerDrawable progressLayerDrawable = new LayerDrawable(progressDrawables);


int status = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // TODO Auto-generated method stub
    setContentView(R.layout.startup);

    bar = (ProgressBar) findViewById(R.id.start_page_progressBar);
    bar.setProgress(0);
    bar.setMax(100);

    progressLayerDrawable.setId(0, android.R.id.background);
    progressLayerDrawable.setId(1, android.R.id.secondaryProgress);
    progressLayerDrawable.setId(2, android.R.id.progress);

    bar.setProgressDrawable(progressLayerDrawable);
}

이를 통해 코드를 통해 ProgressBar에 맞춤 색상을 설정하는 데 도움이되었습니다. 도움이되기를 바랍니다

Muhammad-Adil에 따라 SDK VER 21 이상에 대해 제안했습니다.

android:indeterminateTint="@color/orange"

XML에서는 저에게 효과가 있습니다.

다중 스타일 앱을 다루는 경우 attr을 사용하는 것은 매우 간단합니다.

이 방법을 시도하십시오 :

아래 속성 attrs.xml을 선언하십시오

 <attr name="circularProgressTheme" format="reference"></attr>

Styles.xml로 코드 아래에 붙여 넣습니다

 <style name="ProgressThemeWhite" parent="ThemeOverlay.AppCompat.Light">
        <item name="colorAccent">#FF0000</item>
    </style>

    <style name="circularProgressThemeWhite">
        <item name="android:theme">@style/ProgressThemeWhite</item>
    </style>


  <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

   <item name="circularProgressTheme">@style/circularProgressThemeWhite</item>

 </style>

아래와 같이 진행률 표시 줄을 사용하십시오

  <ProgressBar
        style="?attr/circularProgressTheme"
        android:id="@+id/commonProgress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="visible"/>

수평 진행률 바 사용자 정의 재료 스타일 :

배경의 색상과 수평 진행 막대의 진행 상황을 변경합니다.

<style name="MyProgressBar" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
    <item name="android:progressBackgroundTint">#69f0ae</item>
    <item name="android:progressTint">#b71c1c</item>
    <item name="android:minWidth">200dp</item>
</style>

맞춤형 자재 스타일 및 사용자 정의 진행률 바 확인을 위해 스타일 속성을 설정하여 진행률 표시 줄에 적용하십시오. http://www.zoftino.com/android-progressbar-and-custom-progressbar-examples

수평 진행 상황 바 색을 변경하려면 (Kotlin에서) :

fun tintHorizontalProgress(progress: ProgressBar, @ColorInt color: Int = ContextCompat.getColor(progress.context, R.color.colorPrimary)){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        progress.progressTintList = ColorStateList.valueOf(color)
    } else{
        val layerDrawable = progress.progressDrawable as? LayerDrawable
        val progressDrawable = layerDrawable?.findDrawableByLayerId(android.R.id.progress)
        progressDrawable?.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
    }
}

불확실한 진행 상황을 변경하려면 :

fun tintIndeterminateProgress(progress: ProgressBar, @ColorInt color: Int = ContextCompat.getColor(progress.context, R.color.colorPrimary)){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        progress.indeterminateTintList = ColorStateList.valueOf(color)
    } else {
        (progress.indeterminateDrawable as? LayerDrawable)?.apply {
            if (numberOfLayers >= 2) {
                setId(0, android.R.id.progress)
                setId(1, android.R.id.secondaryProgress)
                val progressDrawable = findDrawableByLayerId(android.R.id.progress).mutate()
                progressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP)
            }
        }
    }
}

그리고 그것은 마지막으로 일반적으로 Pre-Bollipop Progressbar를 착색합니다

tinted progress on api 19

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top