Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 8 MAUI: How to customize the look of the default Page.IsBusy ActivityIndicator on Android?

In .NET MAUI, each page has an IsBusy property that, when true, shows a built-in activity indicator. I just want to know how to change the style of that specific indicator. I tried changing the style of ActivityIndicator in Styles.xaml, but that didn't do anything, so I assume I have to alter something in Platforms>Android>Resources>values but I don't know what.

In a default .NET 8 MAUI app running on Android, when you set IsBusy to True in the AppShell (or any other page), a blue activity indicator runs. I want to change the style of that. Ideally at least the colour. screenshot

like image 787
Cody Avatar asked Oct 23 '25 15:10

Cody


1 Answers

Well, I figure out it.

For built-in activity indicator, it is achieved through MessagingCenter(refer to source code). On specific platform, e.g. Android, it adds and remove ProgressBar to achieve the effect of showing and hiding.

So, get the native view and modify it:

private void Button_Clicked(object sender, EventArgs e)
        {
            IsBusy = !IsBusy;

#if ANDROID
            var progressLayout = Platform.CurrentActivity?.FindViewById(16908999) as Android.Widget.FrameLayout;
            var progressbar = progressLayout?.GetChildAt(0) as Android.Widget.ProgressBar;


           //when IsBusy is false, progressbar will be removed, will be null. So should make a judgment
            if (progressbar != null)
            {
                // set it to red
                var iconColorStates = Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.Red);
                progressbar.IndeterminateTintList = iconColorStates;
            }
#endif

Here is the effect.

like image 198
Jianwei Sun - MSFT Avatar answered Oct 26 '25 06:10

Jianwei Sun - MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!