简体   繁体   English

如何使启动画面变为全屏?

[英]How can I make splash screen to full screen?

I am trying to make splash screen to full screen.我正在尝试将启动画面设为全屏。 Let me explain with images:让我用图片来解释:

在此处输入图片说明

As you can see there is a black bar at the top.如您所见,顶部有一个黑条。 There is also a white navigation bar at the bottom.底部还有一个白色的导航栏。 The black bar at the top comes a few seconds after opening the application and causes the background image to decrease in size.打开应用程序几秒钟后,顶部的黑条就会出现,并导致背景图像尺寸减小。

My splash_screen.xml:我的 splash_screen.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@color/splash_background"/>
    </item>
    <item android:gravity="fill">
        <bitmap
             android:tileMode="disabled"   
             android:gravity="fill"
             android:mipMap="true"
             android:src="@drawable/splash_logo"/>
    </item>
</layer-list>

My styles.xml:我的styles.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="MyTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowActionBar">false</item>
    </style>
    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />

</resources>

My SplashActivity.cs:我的 SplashActivity.cs:

namespace OkuKazan
{
    [Activity(Label = "OkuKazan", Icon = "@mipmap/icon", Theme ="@style/MyTheme.Splash", MainLauncher = true, NoHistory = true)]
    public class SplashActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Create your application here
        }

        protected override async void OnResume()
        {
            base.OnResume();
            await SimulateStartUp();
        }

        async Task SimulateStartUp()
        {
            await Task.Delay(TimeSpan.FromSeconds(3));
            StartActivity(new Intent(Application.Context, typeof(MainActivity)));
        }
    }
}

According to my research they are using something like NavigationPage but as I am a new xamarin user I don't get it.根据我的研究,他们使用的是 NavigationPage 之类的东西,但由于我是新的 xamarin 用户,我不明白。 I would really appreciate if you can help.如果您能提供帮助,我将不胜感激。

EDIT 1:编辑 1:

I edited my styles.xml but it is still not working.我编辑了我的styles.xml 但它仍然无法正常工作。 The black bar at the top and the white bar didn't disappear :(顶部的黑条和白条没有消失:(

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>m>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="windowActionModeOverlay">false</item>
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:textCursorDrawable">@null</item>
        <item name="android:forceDarkAllowed">false</item>
    </style>

    <style name="MyTheme.Splash" parent="AppTheme">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowBackground">@drawable/splash_screen</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />

</resources>

A theme looking something like:一个看起来像这样的主题:

  <style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>m>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="windowActionModeOverlay">false</item>
    <item name="android:windowBackground">@color/white</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:textCursorDrawable">@null</item>
    <item name="android:forceDarkAllowed">false</item>
  </style>

  <style name="AppTheme.Splash" parent="AppTheme">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowBackground">@drawable/bg_splashscreen</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
  </style>

Then use the AppTheme.Splash on your Activity.然后在您的活动中使用AppTheme.Splash This works on one of the Apps I work on.这适用于我工作的应用程序之一。 You can play around with the attributes.你可以玩弄这些属性。 However, the windowFullScreen and windowNoTitle are probably the most important ones.然而, windowFullScreenwindowNoTitle可能是最重要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM