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" />
-
u want change progressbar background color – Jigar Apr 07 '16 at 10:20
-
http://stackoverflow.com/a/13415084/3790150 – saeed Apr 07 '16 at 10:23
3 Answers
You can customize a progress bar. Customizing a ProgressBar requires defining the attribute or properties for the background and progress of your progress bar.
Create an XML file named customprogressbar.xml in your res->drawable folder:
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>
Now you need to set the progressDrawable property in customprogressbar.xml (drawable)
You can do this in the XML file or in the Activity (at run time).
Do the following in your 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);

- 839
- 6
- 12
The question makes no sense at all. In the question you creates a ProgressDialog, which is infact a descendent of Dialog. A Dialog always have a background white/dark based on Application theme.
If you want just a Progress bar in the Activity,
Add
<ProgressBar android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pgBar"
android:indeterminate="true" />
in the Activity/Fragment's layout
And Access the Progressbar like this
ProgressBar pgBar = (ProgressBar) findViewById(R.id.pgBar);
pgBar.setIndeterminate(true);
pgBar.setVisibility(View.Visible)

- 2,603
- 2
- 26
- 36
The default backround for the progress bar is white. We can change the color of the progress bar by using
- android:progressDrawable in xml OR
- setProgressDrawable(drawable) method programically.
A drawable may be an image directly inserted to drawable folder or create a xml file in drawable folder.xml drawable is preferred 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

- 337
- 2
- 16

- 66
- 7