简体   繁体   中英

How to generate a ProgressBar programmatically in Xamarin.Android

I'm trying to create a progress bar programmatically in Xamarin.Android. I need it to be equivalent to the following progress bar created in the axml file.

 <ProgressBar
        android:id="@+id/indeterminateBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:indeterminate="true"
        android:max="100"
        android:layout_below="@+id/framelauout"
        android:indeterminateTint="#5daa30"
        android:visibility="invisible" />

How would i accomplish this in ac# class using android Xamarin.Android platform?

Thanks in advance.

Instead of creating it in xaml, Create it programatically anywhere in the app, with preferred position on screen.

var _pbr = ProgressBar(this, "b");
_pbr.Show();
//your code here
 _pbr.Hide();

ProgressBar method

public ProgressDialog ProgressBar(Context context, string position)
{

    var pbr = new ProgressDialog(context);
    pbr.SetCancelable(false);
    pbr.Indeterminate = true;
    pbr.SetProgressStyle(ProgressDialogStyle.Spinner);
    switch (position.ToLower())
    {
        case "c":
            pbr.Window.SetGravity(GravityFlags.Center);
            break;
        case "b":
            pbr.Window.SetGravity(GravityFlags.Bottom);
            break;

    }
    pbr.SetMessage("please wait..");
    return pbr;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM