Landscape splash-screen in android

How can I have a two different splash-screens from landscape and portrait mode? I have managed to get the portrait splash-screen for my android app, but for a 10" screen this portrait splash-screen seems to stretch the image. Here is my code:

SplashActivity.cs:

    [Activity(Theme = "@style/Theme.Splash", Label = "appName", MainLauncher = true, NoHistory = true, ScreenOrientation = ScreenOrientation.Portrait)]
        public class SplashActivity : Activity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
               // Create your application here
                base.OnCreate(savedInstanceState);
                System.Threading.Thread.Sleep(1000); //Let's wait awhile...
                this.StartActivity(typeof(MainActivity));
            }
        }

Styles.xml

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
      <style name="Theme.Splash" parent="android:Theme">
        <item name="android:windowBackground">@drawable/splash</item>
        <item name="android:windowNoTitle">true</item>
      </style>
    </resources>

And separate splah.png images are place in drawable, drawable-hdpi, drawable-xhdpi and drawable-xxhdpi folders.

Answers

  • Hi, did you find solution for this problem?
    I tried with using drawable and drawable-land folders, but that doesn't solved the problem.

  • Hi, same problem here using splashscreen image only in drawable-land and drawable-port folders and splashscreen is always from port folders

  • DeveshMishraDeveshMishra USMember ✭✭

    Any solution for this issues ?

  • ChristophHuberChristophHuber USMember ✭✭

    Still no solution for this issue?

  • RyanWatsonRyanWatson USMember ✭✭✭
    Running into this same issue. Anyone have a solution?
  • CharwakaCharwaka INMember ✭✭✭✭
    edited November 2017

    Hi @mishtyNaik
    First of all add Landscape orientation also like this

    ScreenOrientation = ScreenOrientation.Portrait | ScreenOrientation.Landscape

    If you're specifying your splash screen layout in XML, you can place a landscape layout in the **res/layout-land **folder and an identically named portrait layout either in the default **res/layout **folder or a specific **res/layout-port **folder

    Or

    You can determine the orientation of the device at build time, and then display the appropriate splash screen

    public DeviceOrientations GetOrientation()
            {
                IWindowManager windowManager = Android.App.Application.Context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();
    
                var rotation = windowManager.DefaultDisplay.Rotation;
                bool isLandscape = rotation == SurfaceOrientation.Rotation90 || rotation == SurfaceOrientation.Rotation270;
                return isLandscape ? DeviceOrientations.Landscape : DeviceOrientations.Portrait;
            }
    

    Don't Forget to mark as answer

  • MatthiasBruzekMatthiasBruzek USMember ✭✭

    Just use a values-land folder and put the following Styles.xml there:

    <?xml version="1.0" encoding="utf-8" ?>
    <resources>
      <style name="MyTheme.Splash" parent ="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_landscape</item>
        <item name="android:windowNoTitle">true</item>
      </style>
    </resources>
    

    Add splash_landscape.png to your drawables and set the parent theme you like.

  • StarclusterStarcluster Member ✭✭

    I tried the suggested solutions above - without success...
    Anyone got this work?

  • BhaurajBiradar.9064BhaurajBiradar.9064 USMember ✭✭✭

    No, It didn't worked for me :(
    @MatthiasBruzek - I added folder, image with same names. It didn't worked for me :(

  • MatthiasBruzekMatthiasBruzek USMember ✭✭

    Hi @Starcluster, @BhaurajBiradar.9064

    Have a look at this minimal sample.

    Important parts:

    // MainActivity.cs
    using Android.App;
    using Android.Widget;
    using Android.OS;
    
    namespace LandscapeSplash
    {
        [Activity(Label = "LandscapeSplash", MainLauncher = true, Theme = "@style/MyTheme.Splash")]
        public class MainActivity : Activity
        {
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
    
                // Set our view from the "main" layout resource
                SetContentView(Resource.Layout.Main);
            }
        }
    }
    
    // Resources/values/Styles.xml
    <?xml version="1.0" encoding="utf-8" ?>
    
    <resources>
      <style name="MyTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash</item>
        <item name="android:windowNoTitle">true</item>
      </style>
    </resources>
    
    // Resources/values-land/Styles.xml
    <?xml version="1.0" encoding="utf-8" ?>
    
    <resources>
      <style name="MyTheme.Splash" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_landscape</item>
        <item name="android:windowNoTitle">true</item>
      </style>
    </resources>
    

    ... and, obviously, Resources/drawable/splash.PNG and Resources/drawable/splash_landscape.PNG

  • BhaurajBiradar.9064BhaurajBiradar.9064 USMember ✭✭✭

    @MatthiasBruzek - Thank you, your solution worked for me :)

  • StarclusterStarcluster Member ✭✭

    OK, my problem is the home screen in portrait mode. For example, my tablet supports the landscape mode in the home screen. Than the landscape image is selected correctly. If not, the portrait screen will be shown and when it disappears, the app changes automatically to landscape mode. Would be nice when the app notices the landscape mode before the splash screen appears.

  • pratik90pratik90 INMember ✭✭

    HI @Starcluster ,

    Have you found any solution for this?

    Thanks.

  • StarclusterStarcluster Member ✭✭

    @pratik90: No, i couldn't find any solution for the home screen in portrait mode yet. It only works if the home screen is in landscape mode.

Sign In or Register to comment.