1

So, I implemented a splash screen using the android:windowBackground attribute. Basically I've an style for my LoginActivity (first screen that pops up on the App)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="MyLoginTheme" parent="MyAppTheme">
        <item name="android:windowBackground">@drawable/drawable_login_background</item>
    </style>
</resources>

And I've that drawable drawable_login_background which basically is a layer list with the image and a blue overlay:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <bitmap android:src="@drawable/ic_login_background_xhdpi"/>
    </item>
    <item>
        <color android:color="@color/blueOverlay"/>
    </item>
</layer-list>

It looks perfect on my Samsung J7 (h1280xw720, xhdpi) but It looks kinda off on my Moto G Play (h1400x720, xhdpi). The thing is that both devices are xhdpi so I cannot use the drawable folder to pick different drawables with different sizes.

Is there a way that I can pick different drawables based just on the height?

Note

Please notice that the windowsBackground attribute takes a drawable, some folks had mentioned to use the layout-swWIDTH-shHEIGHT layout folders, but those folders are to load different layouts depending on the screen height and size. I'm not using windowsBackground just for the sake of using it, setting the style of the app with a windowsBackground allows you to display much more quickly the splash screen.

4gus71n
  • 3,717
  • 3
  • 39
  • 66
  • Possible duplicate of [Android devices with different height takes same layout folder](https://stackoverflow.com/questions/29025843/android-devices-with-different-height-takes-same-layout-folder) – Martin Zeitler Jan 03 '19 at 01:11
  • @MartinZeitler Sorry but since I'm using the windowsBackground attribute and loading a drawable, using the layouts folder isn't going to work. I cannot set a layout as drawable for the windowsBackground attribute. – 4gus71n Jan 03 '19 at 13:12
  • The previous commenter is also suggesting to do it with an ImageViee instead. I will argue that an ImageView using a vector would be the best solution. You could use a vector on your list, but the scaletype attribute of an ImageView will allow you to compensate for some intermediates screen sizes – cutiko Jan 04 '19 at 00:39
  • @cutiko Sorry I really wanna fix it using the windowsBackground. Sorry for being so stubborn, but I found out that using the windowsBackground works really good for some devices. Yeah, I could use a layout for the splash screen on a dummy activity or something like that, and set the windowsBackground to null so I don't display any background color when the App opens, but on some devices when we do this, and we open the App, It delays a couple of seconds (showing the null windowsBackground) until the Activity pops up. – 4gus71n Jan 04 '19 at 11:08
  • check my solution to this here. I guess the issue is the API and not the resolution.https://stackoverflow.com/questions/39172899/splashscreen-with-vector-stretched-full-screen/60558138#60558138 – quealegriamasalegre Mar 06 '20 at 05:49

1 Answers1

0

Simple solution, I ended up dragging the drawable for my Samsung 1280x720 into the drawable folder and my larger drawable for my Moto G Play 1440x720 into drawable-large. I guess that if you want to differentiate between xhdpi, hdpi and so on you just need to add the qualifier to the end.

I never realized that if you do a right click in the res folder on Android Studio and tap on Create new Resource Directory you can pick the qualifiers that you want to match from the left and builds the directory's name for you.

4gus71n
  • 3,717
  • 3
  • 39
  • 66