FadeTo() not working in Android API level 23 and lower

CraftedGamingCraftedGaming Member
edited September 2018 in Xamarin.Android

I'm trying to fade an image similar to what a Splash Screen does. I have my project / app on a cross-platform but this one specifically bugs out in Android. I've been testing FadeTo(opacity, milliseconds) and it won't work on my Android phone API 22. I tested the same code on a different phone (API 26) and it worked. My friend told me it had something to do with the FadeTo() function being not available for API 23 and below. I'd like to ask for a workaround for this. I'm only seeing my logo appear right after the app has loaded.

I've tried the following approach. Please note that logo is the Image view that I'm trying to fade in the screen. I've set its opacity to zero just so everyone knows. And that I'm running them in Device.BeginInvokeOnMainThread()

attempt 1:

in SplashScreenPage.xaml.cs constructor. this worked on another phone whose API is 26 but not on API 22

    Device.BeginInvokeOnMainThread(async () =>
                {
                    await ViewExtensions.FadeTo(logo, 1, 2000, Easing.Linear);
                });

attempt 2:
this time, I'm calling ChangeOpacity() from the BeginInvokeOnMainThread()

async void ChangeOpacity()
        {
            await ViewExtensions.FadeTo(logo, 1, 3000);
        }

attempt 3:
hacky way of trying to do it

async void ChangeOpacity()
        {
            await logo.FadeTo(0.2, 3000);
            Task.Delay(3000).Wait();
            await logo.FadeTo(0.4, 3000);
            Task.Delay(3000).Wait();
            await logo.FadeTo(0.6, 3000);
            Task.Delay(3000).Wait();
            await logo.FadeTo(0.8, 3000);
            Task.Delay(3000).Wait();
            await logo.FadeTo(1, 3000);
            Task.Delay(3000).Wait();
        }

attempt 4:
last resort

async void ChangeOpacity()
        {
            for (double o = logo.Opacity + 0.01; o < 1f; o += 0.01)
            {
                logo.Opacity = o;
                Task.Delay(100).Wait();
            }
        }

I've posted this same question on stackoverflow ; however, no one was able to answer it. I'm hoping someone here can help me.

Posts

Sign In or Register to comment.