My bitmap is not always displayed in the same size on my Android tablet. It looks bigger when I use it as splash screen.

Kim Strasser 1,036 Reputation points
2023-11-22T16:32:58.3733333+00:00

I use a png bitmap file in my splash screen. In addition, I have tried to display exactly the same image with ImageView but then the bitmap looks much smaller on my Android tablet.

The image resolution is 288x288 px and I use the same image resolution in the drawable folders because I'm not sure which resolutions I should use for each folder. I have added the image splash_logo to the following drawable folders:

drawable-mdpi

drawable-hdpi

drawable-xhdpi

drawable-xxhdpi

drawable-xxxhdpi

The file ic_splash_screen_image.xml is located in the folder Drawable:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <color android:color="@color/splash_background"/>
  </item>
  <item>
    <bitmap
        android:src="@drawable/splash_logo"
        android:tileMode="disabled"
        android:gravity="center"/>
  </item>
</layer-list>

The files colors.xml and styles.xml are located in the folder Values:

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
  <color name="splash_background">#000000</color>
  <color name="custom_color">#4cb3fc</color>
</resources>
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
     <style name="MainTheme" parent="MainTheme.Base">
    </style>
    <style name="MainTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
         <item name="android:windowFullscreen">true</item>
        <item name="android:colorPrimary">#2196F3</item>
        <item name="android:colorPrimaryDark">#1976D2</item>
        <item name="android:colorAccent">#FF4081</item>
         <item name="android:windowLightStatusBar">false</item>
        <item name="android:windowActionModeOverlay">true</item>
        <item name="android:windowIsTranslucent">true</item>
    </style>
    <style name="SplashTheme" parent ="Theme.SplashScreen">
    <item name="windowSplashScreenBackground">@android:color/black</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_splash_screen_image</item>
	<item name="postSplashScreenTheme">@style/MainTheme</item>
	<item name="android:windowLightStatusBar">true</item>
  </style>
</resources>

In Activity1.cs, I ise the following code to draw the image:

[Activity(
Label = "@string/app_name",
MainLauncher = true,
Icon = "@mipmap/icon",
Theme = "@style/SplashTheme",
AlwaysRetainTaskState = true,
LaunchMode = LaunchMode.SingleInstance,
ScreenOrientation = ScreenOrientation.UserLandscape,         ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize
)]

public class Activity1 : AndroidGameActivity, ViewTreeObserver.IOnGlobalFocusChangeListener
{

FrameLayout layout;
View splashView;

protected override void OnCreate(Bundle bundle)
{
    AndroidX.Core.SplashScreen.SplashScreen.InstallSplashScreen(this);
    base.SetTheme(Resource.Style.MainTheme);
    base.OnCreate(bundle);

    layout = new FrameLayout(this.ApplicationContext);
    layout.AddView((View)_game.Services.GetService(typeof(View)));           
    splashView = new ImageView(this.ApplicationContext);
    ((ImageView)splashView).SetBackgroundResource(Resource.Drawable.ic_splash_screen_image);
    layout.AddView(splashView);
    SetContentView(layout);
}
}

Why does the bitmap look much smaller when I use ImageView instead of the splash screen to draw the bitmap?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,357 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,962 questions
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 43,371 Reputation points Microsoft Vendor
    2023-11-24T07:51:09.6866667+00:00

    Hello,

    I've noticed that the way you set up splashscreen is based on setting up a new activity in the Xamarin documentation.

    This is actually the splashscreen setup method for older versions of Android, and the ImageView is not automatically resized as an icon, so the icons you set to multiple resolutions won't actually work.

    For the best practices for setting up splashscreen on Android, please refer to this official Google documentation.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Graham McKechnie 416 Reputation points
    2023-11-25T00:44:03.3866667+00:00

    You can't use the old layer-list xmlns:android technique once you moved to Android12+. The following link shows how to do a splash screen for Android 12 and above. https://github.com/gmck/XamarinBasicSplashScreen. There is also a Net7 version of the same app, which could just as easily be converted to a Net8 version.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.