【问题标题】:Splash screen with Tabbed main page Xamarin forms带有选项卡式主页 Xamarin 表单的启动画面
【发布时间】:2020-05-27 19:12:15
【问题描述】:

我是移动应用开发的初学者,我正在为一个项目使用 Xamarin 表单开发一个 android 应用。

在我的 Xamarin 表单项目中,我必须在启动时添加启动画面。为此,我必须将此代码放在我的 MainPage.XAML

<Grid>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />

        <Grid x:Name="SplashGrid" BackgroundColor="{StaticResource Primary}">
            <Image x:Name="Logo" Source="Logo" HorizontalOptions="Center" VerticalOptions="Center">
                <Image.TranslationY>
                    <OnPlatform x:TypeArguments="x:Double">
                        <On Platform="Android">-12</On>
                    </OnPlatform>
                </Image.TranslationY>
            </Image>
        </Grid>
    </Grid>

但我的主页是选项卡式页面,而不是内容页面。

在我的主页保持选项卡状态时,我可以做些什么来实现启动画面?

如果我的标签页可以在加载主页后自动打开,那也很好。

这就是我的 App.xaml.cs 的构造函数的外观。

public App()
        {
            InitializeComponent();
            MainPage = new NavigationPage(new TabbedPageContainer()); 
        }

非常感谢您的帮助。 提前致谢。

【问题讨论】:

    标签: c# android xaml xamarin.forms


    【解决方案1】:
    public class App : Application
    {
        public App()
        {
            InitializeComponent();
        }
    
        protected override async void OnStart()
        {
            // show the splash
            MainPage = new SplashPage();
            // simple wait or initialize some services
            await Task.Delay(2000); 
            // show the real page
            MainPage = new NavigationPage(new TabbedPageContainer()); 
        }
    }
    

    【讨论】:

    • 我相信 Splash 是我们在应用加载其第一页之前显示的内容,只是为了避免出现空屏,如果您在 App.cs 中分配 splash,那么它只会像第一页一样工作,实际上在启动时会有空白屏幕。
    • @MShah 请看一下问题:OP 在 MainPage 上发布了带有 Splash 图像的代码 - 但他不能再使用它了,因为现在应用程序正在使用带有 TabbedPageContainer 的 NavigationPage
    • 但是可以做的是创建这样的启动活动:c-sharpcorner.com/UploadFile/1e050f/…
    • 这样它就可以作为启动画面直接启动标签页了
    • @MShah OP 说:在我的 Xamarin 表单项目中,我必须在启动时添加启动画面。要做到这一点,我必须将此代码放在我的 MainPage.XAML 上 - 随时自行发布答案,但对我而言,我的答案正是 OP 所要求的(页面上的启动图像)
    【解决方案2】:

    通常,我们使用可绘制资源来创建启动画面。请遵循以下步骤。

    您可以按照以下链接上的步骤进行操作。它在标签页上运行良好。 Xamarin forms custom splash screen

    有关IOS的更多信息,您可以查看链接。

    https://medium.com/@thesultanster/xamarin-splash-screens-the-right-way-3d206120726d https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/splashscreen

    【讨论】:

      猜你喜欢
      • 2017-03-04
      • 1970-01-01
      • 2017-10-11
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多