Xamarin.Forms implement AndHud and BTProgressHud

只愿长相守 提交于 2019-12-03 16:47:30

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 ();
Timothy Lee Russell

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

Loading Icon for layout screen Xamarin android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!