Junaid Pathan
Junaid Pathan

Reputation: 4336

How to show ProgressBar in Xamarin.Android?

I want to show a ProgressBar while doing some activity as ProgressDialog is deprecated Xamarin.Android. I have searched everywhere, but I didn't find how to implement ProgressBar. This is my XML code:

<ProgressBar
    android:id="@+id/ProgressBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@android:style/Widget.Material.ProgressBar.Horizontal" />

I am able to show the progress bar, but how to show it progressing while doing some activity like incrementing counter till 100.

Upvotes: 0

Views: 648

Answers (1)

Timo Salom&#228;ki
Timo Salom&#228;ki

Reputation: 7189

The ProgressBar control has a property called Progress which you need to modify. By default, the minimum and maximum values are 0 and 100, so you don't even need to change them.

In a nutshell, you can update the progress in the activity like this:

var pb = FindViewById<ProgressBar>(Resource.Id.ProgressBar);

pb.Progress = 25;
// or alternatively
pb.IncrementProgressBy(30);

You can also define the starting progress in your XML like the following:

<ProgressBar
    android:id="@+id/ProgressBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:progress="25"
    style="@android:style/Widget.Material.ProgressBar.Horizontal" />

Upvotes: 1

Related Questions