Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms implement AndHud and BTProgressHud

Can anyone point me to a Xamarin.forms sample that utilises AndHud for Android and BTProgressHud for iOS (or anything similar)?

I know there is the ACR-Xamarin-Forms example here https://github.com/aritchie/acr-xamarin-forms, but it is way too complicated and completely over my head.

Surely there is a more simple easy to understand implementation, but if not some sort of guidance on how to get started on implementing it (for a C# and Xamarin newbie)

Thanks in advance

like image 789
user1667474 Avatar asked Dec 14 '22 19:12

user1667474


2 Answers

This is how I've done it for iOS. All you should need to do for Android is create an implementation of IHud that using AndHud instead of BTProgressHud.

First, create an interface in the shared project

public interface IHud
{
    void Show();
    void Show(string message);
    void Dismiss();
}

Next, in the iOS project, create an implementation of IHud using BTProgressHud component:

[assembly: Dependency(typeof(Hud))]
namespace project.iOS
{
    public class Hud : IHud
    {
        public Hud ()
        {
        }

        public void Show() {
            BTProgressHUD.Show ();
        }

        public void Show(string message) {
            BTProgressHUD.Show (message);
        }

        public void Dismiss() {
            BTProgressHUD.Dismiss ();
        }
    }
}

Finally, to utilize this from Forms code, just do

    var hud = DependencyService.Get<IHud> ();
    hud.Show ("Loading Vehicles");

    // tasks...

    hud.Dismiss ();
like image 78
Jason Avatar answered Dec 30 '22 20:12

Jason


My answer, which is quite similar to @jason's can be found here:

Loading Icon for layout screen Xamarin android

like image 21
Timothy Lee Russell Avatar answered Dec 30 '22 20:12

Timothy Lee Russell