0
votes

I have been reading much about Xamarin for sometime and how to make a splash screen. I am quite new to something like this and hence i wanted to ask on here, Why is the splash screen not redirecting to the login page in the Emulator'

i am using Visual Studio 2019, I added a new folder drawable-hdpi and then added the images to it to be used inside the xaml. Now what? it does not redirect!

Here is what my code looks like

Splash screen Xaml (MainPage.xaml)

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             x:Class="VisitorMan.MainPage"
             BackgroundColor="#fff">

    <StackLayout HorizontalOptions="Center" VerticalOptions="Center" Padding="10">
        <Image Source="splash_logo.png" x:Name="imgLogo" HeightRequest="150" WidthRequest="150"/>
    </StackLayout>

</ContentPage>

The corresponsing MainPage.xaml.cs File Looks like this

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace VisitorMan
{
    // Learn more about making custom code visible in the Xamarin.Forms previewer
    // by visiting https://aka.ms/xamarinforms-previewer
    [DesignTimeVisible(false)]
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
            Animate();
        }

        public async Task Animate() 
        {
            imgLogo.Opacity = 0;
            await imgLogo.FadeTo(1, 4000);
            Application.Current.MainPage = new LoginPage();
        }
    }
}

The Login Page which shows the username and password (LoginPage.xaml) Looks like this

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             x:Class="VisitorMan.LoginPage"
             BackgroundColor="#fff">

    <ContentPage.Content>
        <StackLayout Spacing="20" Padding="50" VerticalOptions="Center">
            <Image Source="splash_logo.png" x:Name="imgLogo" HeightRequest="150" WidthRequest="150"/>
            <Entry Placeholder="Username"></Entry>
            <Entry Placeholder="Password" IsPassword="True"></Entry>
            <Button Text="Log In" TextColor="White" BackgroundColor="#ff77D065"></Button>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

The splashscreen is just standstill and does not redirect to the Login Page. Could there be something i am missing?

2
Hi, I have checked shared code in my local project , there is no problem. You can share the screenshot of Resources folder in Android . Make sure the name of image is correct used in Forms and be reaally add to project.Junior Jiang
@JuniorJiang-MSFT, it does not redirect to the main Login screen from the splashscreen. hence I concluded , thats what the worry isJin
Okey , have a try with updating VS and Xamarin Forms to the latest version . If also not , share sample project here , will check it .Junior Jiang
Still the same, here is the download link gofile.io/?c=GYDOqWJin
i use Visual Studio 2019 and Android StudioJin

2 Answers

0
votes

I didn't check but you can try this

public async Task Animate() 
{
    imgLogo.Opacity = 0;
    await imgLogo.FadeTo(1, 4000);
    Device.BeginInvokeOnMainThread(() =>
    {
       Application.Current.MainPage = new LoginPage();
    });
}
0
votes

I have tried shared sample , the problem is that you need to update nuget packages (especially version of Xamarin.Forms) of project to the latest version.

Right click Solution of project , choose Manage Nuget Packages For Solution...

enter image description here

After Updated :

enter image description here

The effect :

enter image description here