2015-12-01 15 views
21

używam ProgressDialog za pokazanie ProgressbarJak zmienić domyślny ProgressDialog kolor okrąg w Android

  ProgressDialog progressDialog = new ProgressDialog(context); 
      progressDialog.setCancelable(false); 
      progressDialog.setMessage(message); 
      progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
      progressDialog.show(); 

I to zbliża się ten

enter image description here

chcę zmienić na zielony kolor okrąg do czerwonego. czy jest jakiś sposób?

Próbowałem

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

, ale nie działa.

+0

http://stackoverflow.com/questions/4908289/styling-progress-dialog-in-android –

+2

Możliwy duplikat [Jak zmienić kolor paska postępu w postępie w systemie Android] (http://stackoverflow.com/questions/2020882/how-to-change-progress-bars-progress-color-in-android) –

+0

Może być duplikatem pytania. Proszę sprawdzić this

Odpowiedz

4

Spróbuj tego:

Przykład gdzie ustawienie koloru czerwonego:

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

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

W swojej Application tematu, zmień colorAccent

<style name="AppTheme.Bash" parent="Theme.AppCompat.Light.DarkActionBar"> 
    <item name="colorPrimary">@color/colorPrimary</item> 
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item> 
    <item name="colorAccent">Add your color here</item> 
    <item name="android:windowBackground">@color/gray</item> 
</style> 

użytkowania niezależnie od koloru chcesz

+1

Nie działa na API21 – PassKit

31

W style.xml utworzyć styl okna dialogowego dla:

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> 
<item name="colorAccent">@color/black</item> 
<item name="android:textColorPrimary">@color/white</item> 
<item name="android:background">@color/grey_dialog_box</item> 
</style> 

W tym "android:textColorPrimary" konieczność określenia koloru, który chcesz pokazać, a w kodzie java zdefiniować styl z ProgressDialog jak:

ProgressDialog progressDialog = new ProgressDialog(context,R.style.AppCompatAlertDialogStyle); 

Więcej: http://androidprogressdialogcustomcolor.blogspot.in/

+5

To nie zmienia koloru okrągłego kształtu – Abhishek

+0

Również "pokaż" jest statyczne i nie działa z nowym wystąpieniem ProgressDialog. – mwieczorek

+0

to nie obsługuje pre Lollipop (API 21) –

4

enter image description here

Utwórz układ dla okna postępu nazwanego jako niestandardowy _progress_dialog.xml w folderze układu.

<?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="56dip" android:height="56dip" /> 

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

    </shape> 
</rotate> 

upewnić, że indeterminate = true i android:indeterminateDrawable="@drawable/custom_progress_background" w układzie działalności, w których chcesz używać ładowacz

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/loadingPanel" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center"> 

    <ProgressBar 
     android:layout_width="wrap_content" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_height="wrap_content" 
     android:indeterminateDrawable="@drawable/custom_progress_dialog" 
     android:indeterminate="true" /> 
</RelativeLayout> 
6

nie jest to idealne rozwiązanie, ale może pomóc.

Sprawdź również mój poprzedni komentarz. https://stackoverflow.com/a/39687893/2598453

final ProgressDialog progress = new ProgressDialog(this); 
progress.setMessage(getString(R.string.progress_message)); 
progress.setIndeterminate(true); 
progress.setCancelable(false); 

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { 
    Drawable drawable = new ProgressBar(this).getIndeterminateDrawable().mutate(); 
    drawable.setColorFilter(ContextCompat.getColor(this, R.color.colorAccent), 
      PorterDuff.Mode.SRC_IN); 
    progress.setIndeterminateDrawable(drawable); 
} 

progress.show(); 
0

idealne i proste rozwiązanie dla paska postępu zwyczaj kolor. Custom Progress bar

public class CustomProgressBar extends ProgressBar{ 
    public CustomProgressBar(Context context) { 
     super(context); 
     this.setIndeterminate(true); 
     this.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.app_blue), PorterDuff.Mode.MULTIPLY); 
    } 

    public CustomProgressBar(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     this.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.app_blue), PorterDuff.Mode.MULTIPLY); 
    } 

    public CustomProgressBar(Context context, AttributeSet attrs, int defStyleAttr) { 
     super(context, attrs, defStyleAttr); 
    } 
} 

i używać go w swoim układzie.

<RelativeLayout 
     android:id="@+id/loadingPanel" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:visibility="gone"> 

     <com.mayproject.views.CustomProgressBar 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </RelativeLayout> 
0

Jeśli chcesz zdefiniować kolor ad-hoc, bez konieczności dziedziczenia lub dedykowanego XML, można użyć coś takiego:

/** Styles a ProgressDialog to use a themed Spinner. */ 
public void setStyledProgressDialog(final Context pContext, final ProgressDialog pProgressDialog, final int pColorResourceId) { 
    // Allocate a new ProgressBar. 
    final ProgressBar lProgressBar = new android.widget.ProgressBar(pContext, null, android.R.attr.progressBarStyle); 
    // Configure the IndeterminateDrawable. 
    lProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(pContext, pColorResourceId), android.graphics.PorterDuff.Mode.MULTIPLY); 
    // Assign the ProgressBar to the ProgressDialog. 
    pProgressDialog.setIndeterminateDrawable(lProgressBar.getIndeterminateDrawable()); 
} 
0

Jeśli już używać materiału dialogi biblioteki (https://github.com/afollestad/material-dialogs#indeterminate-progress-dialogs) najprostszym rozwiązaniem może być użycie okna dialogowego postępu z tej biblioteki. Krąg zostanie automatycznie zabarwiony podstawowego koloru:

MaterialDialog dialog = new MaterialDialog.Builder(context) 
        .content(R.string.loading) 
        .progress(true, 0) 
        .show(); 
Powiązane problemy