简体   繁体   中英

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:

<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:

<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:

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. I would really appreciate if you can help.

EDIT 1:

I edited my styles.xml but it is still not working. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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