Is there an easy way to display an ActivityIndicator over the top of other layout?

EasyGoingPatEasyGoingPat GBMember ✭✭✭

Can anyone suggest a way or point me at code to display an ActivityIndicator, ideally over the top of any existing visual elements already in the XAML tree?

Two possible ways of doing this come to mind. I could include an ActivityIndicator somewhere in the XAML for each page and simply make is visible and invisible as required. Or a better solution would probably be to add the ActivityIndicator to the visual tree using code when required. My use case allows for either of these solutions.

The only way I have got this to work so far is to add the ActivityIndicator into a cell of a Grid, which is not ideal and certainly isn't an option on all screens. So I'd be extremely grateful if anyone can point me at something to help with this.

Kind wishes ~ Patrick

Best Answers

  • M_Shah04M_Shah04 US ✭✭✭
    Accepted Answer

    You can use this plugin to display the same, that is Acr.UserDialogs.

    Steps to use:
    Install plugin
    Initialize in Main Activity: UserDialogs.Init(this);
    To display use: UserDialogs.Instance.ShowLoading();
    To hide use: UserDialogs.Instance.HideLoading();

    Refer this for more detail: https://github.com/aritchie/userdialogs
    https://devlinduldulao.pro/how-to-use-acr-userdialogs/

    Hope this may solve your issue.

  • ClintStLaurentClintStLaurent US ✭✭✭✭✭
    Accepted Answer

    I usually make a "BusyPopup" class using rg.plugins.popups then use that throughout the app.

  • EasyGoingPatEasyGoingPat GB ✭✭✭
    Accepted Answer

    @M_Shah04
    @ClintStLaurent

    Thanks guys. I've marked both your replies as answers because I have no doubt that they would solve my problem. For now, I have chosen instead an inelegant but simple solution (shown below). I felt Acr.UserDialogs pulled in too much stuff and wasn't sure it would build with .NETStandard (one of its sub-components I tried didn't). And I wasn't sure how rg.plugins.popups plugs into the Xamarin navigation system, 'cos it came with a warning not to use the normal Xamarin navigation and I don't want to bugger about with my working navigation right now.

    My solution was to put a Xamarin ActivityIndicator in each page, which begins disabled and invisible. Then whenever I want to turn it on, I just set it to be visible and enabled. Because I use RelativeLayout (which I was anyway), I can overlay it with other elements without upsetting them. As I said, it's ugly, but it works for now.

    Thanks for the suggestions.

    Kind wishes ~ Patrick

  • ClintStLaurentClintStLaurent US ✭✭✭✭✭
    Accepted Answer

    @EasyGoingPat
    Its not in conflict. More like its in parallel. You can back out of your page... or you can remove a popup... independently of each other. If you have a popup displayed and you navigate a page is happens underneath your popup. So there is no reason you can't have a small stillDownloadingPopup in the corner while you still navigate around your page. Or use a popup to make a pseudo-FAB button.

  • NMackayNMackay GB mod
    Accepted Answer

    @EasyGoingPat

    Been in a training course all day, the question has been answered, Rg.Plugins has it's own navigation service and can be injected into your code behind of view Models, it maintains it's own navigation stack. You can use Rg.Plugins with the forms navigation stack but the author doesn't recommend it. If your using Prism you can use a Plugin and can pass parameters back and forth to popups which is pretty cool.

Answers

  • M_Shah04M_Shah04 USMember ✭✭✭
    Accepted Answer

    You can use this plugin to display the same, that is Acr.UserDialogs.

    Steps to use:
    Install plugin
    Initialize in Main Activity: UserDialogs.Init(this);
    To display use: UserDialogs.Instance.ShowLoading();
    To hide use: UserDialogs.Instance.HideLoading();

    Refer this for more detail: https://github.com/aritchie/userdialogs
    https://devlinduldulao.pro/how-to-use-acr-userdialogs/

    Hope this may solve your issue.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    Accepted Answer

    I usually make a "BusyPopup" class using rg.plugins.popups then use that throughout the app.

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭
    Accepted Answer

    @M_Shah04
    @ClintStLaurent

    Thanks guys. I've marked both your replies as answers because I have no doubt that they would solve my problem. For now, I have chosen instead an inelegant but simple solution (shown below). I felt Acr.UserDialogs pulled in too much stuff and wasn't sure it would build with .NETStandard (one of its sub-components I tried didn't). And I wasn't sure how rg.plugins.popups plugs into the Xamarin navigation system, 'cos it came with a warning not to use the normal Xamarin navigation and I don't want to bugger about with my working navigation right now.

    My solution was to put a Xamarin ActivityIndicator in each page, which begins disabled and invisible. Then whenever I want to turn it on, I just set it to be visible and enabled. Because I use RelativeLayout (which I was anyway), I can overlay it with other elements without upsetting them. As I said, it's ugly, but it works for now.

    Thanks for the suggestions.

    Kind wishes ~ Patrick

  • NMackayNMackay GBInsider, University mod

    @ClintStLaurent said:
    I usually make a "BusyPopup" class using rg.plugins.popups then use that throughout the app.

    Did the exact same thing for busy with cancellation support, alert/info/decision and probably going to add a picker one soon. Works a treat. Rg.Plugins adds so much more.

  • EasyGoingPatEasyGoingPat GBMember ✭✭✭

    @NMackay

    I'd be interested to know how you handle the fact that rg.plugins.popups appears to come with its own navigation system. Doesn't this conflict with the Xamarin one?

    • Patrick
  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭
    Accepted Answer

    @EasyGoingPat
    Its not in conflict. More like its in parallel. You can back out of your page... or you can remove a popup... independently of each other. If you have a popup displayed and you navigate a page is happens underneath your popup. So there is no reason you can't have a small stillDownloadingPopup in the corner while you still navigate around your page. Or use a popup to make a pseudo-FAB button.

  • NMackayNMackay GBInsider, University mod
    Accepted Answer

    @EasyGoingPat

    Been in a training course all day, the question has been answered, Rg.Plugins has it's own navigation service and can be injected into your code behind of view Models, it maintains it's own navigation stack. You can use Rg.Plugins with the forms navigation stack but the author doesn't recommend it. If your using Prism you can use a Plugin and can pass parameters back and forth to popups which is pretty cool.

Sign In or Register to comment.