2016-04-07 10 views
1
private static ProgressDialog pDialog; pDialog = new ProgressDialog(activity); 
pDialog.setIndeterminate(true); 
pDialog.setCancelable(false); 

<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:indeterminate="false" /> 
+0

Sie wollen chang e Fortschrittsbalkenhintergrundfarbe – iOS

+0

http://Stackoverflow.com/a/13415084/3790150 – saeed

Antwort

1

Sie können einen Fortschrittsbalken anpassen. Um eine ProgressBar anzupassen, müssen Sie das Attribut oder die Eigenschaften für den Hintergrund und den Fortschritt Ihrer Fortschrittsanzeige definieren.

eine XML-Datei erstellen customprogressbar.xml in Ihrem res- namens> ziehbar Ordner:

custom_progressbar.xml

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

    <!-- Define the background properties like color etc --> 
    <item android:id="@android:id/background"> 
    <shape> 
     <gradient 
       android:startColor="#000001" 
       android:centerColor="#0b131e" 
       android:centerY="1.0" 
       android:endColor="#0d1522" 
       android:angle="270" 
     /> 
    </shape> 
    </item> 

    <!-- Define the progress properties like start color, end color etc --> 
    <item android:id="@android:id/progress"> 
    <clip> 
     <shape> 
      <gradient 
       android:startColor="#007A00" 
       android:centerColor="#007A00" 
       android:centerY="1.0" 
       android:endColor="#06101d" 
       android:angle="270" 
      /> 
     </shape> 
    </clip> 
    </item> 
</layer-list> 

Jetzt müssen Sie die progressDrawable Eigenschaft in customprogressbar.xml einzustellen (ziehbar)

Sie können dies in der XML-Datei oder in der Aktivität (zur Laufzeit) tun.

Gehen Sie wie folgt in Ihrem XML:

<ProgressBar 
    android:id="@+id/progressBar1" 
    style="?android:attr/progressBarStyleHorizontal" 
    android:progressDrawable="@drawable/custom_progressbar"   
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" /> 
At run time do the following 

// Get the Drawable custom_progressbar      
    Drawable draw=res.getDrawable(R.drawable.custom_progressbar); 
// set the drawable as progress drawable 
    progressBar.setProgressDrawable(draw); 
0

Die Frage macht überhaupt keinen Sinn. In der Frage erstellen Sie einen ProgressDialog, der eigentlich ein Nachfolger von Dialog ist. Ein Dialog hat immer einen Hintergrund weiß/dunkel basierend auf dem Anwendungsthema.

Wenn Sie nur ein Fortschrittsbalken in der Aktivität wollen,

hinzufügen

<ProgressBar android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/pgBar" 
android:indeterminate="true" /> 

in der Aktivität/Fragment Layout

und Zugriff auf die Progressbar wie diese

ProgressBar pgBar = (ProgressBar) findViewById(R.id.pgBar); 
pgBar.setIndeterminate(true); 
pgBar.setVisibility(View.Visible) 
0
The default backround for the progress bar is white.We can change the color of the progress bar by using 

1. android:progressDrawable in xml OR 
2. setProgressDrawable(drawable) method programically. 

drawable may be an image directly inseted to drawable folder or create a xml file in drawable folder.xml drawable is prefered since it is more optimal than image. 

ProgressBar progessBar = new ProgressBar(MainActivity.this); 
     Drawable dr=getResources().getDrawable(R.drawable.pink); 
     pDialog.setProgressDrawable(dr); 


where pink.xl is the xml file that describes the background for the progressbar 
Verwandte Themen