Home > Software engineering >  Problem margin/padding for DialogFragment after implementing the new API SplashScreen
Problem margin/padding for DialogFragment after implementing the new API SplashScreen

Time:10-31

I added the new Splashscreen API (androidx.core:core-splashscreen:1.0.0-rc01) on my app, after that my margins/paddings are broken but only for my launcher activity (MainActivity) especially for dialog fagments opened from this activity. In other activities, no problem, everything is working fine.

Below, my dialog fragment without the Splashscreen implemented, my paddings/margins are OK : Margin and padding OK without Splashscreen

And now with Splashscreen implementation :

[Margin and padding broken withSplashscreen2

I followed instructions from the developer Android doc here : https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen

In my MainActivy.kt

    override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
        super.onCreate(savedInstanceState)

In the Manifest.xml, I added the code below in my MainActity

android:theme="@style/AppTheme.AppStarting"

In my Splashscreen theme, I have set the "postSplashScreenTheme" to my original theme

<style name="AppTheme.AppStarting" parent="Theme.SplashScreen">
    <item name="postSplashScreenTheme">@style/AppTheme</item>
    <item name="windowSplashScreenBackground">@color/white</item>
    <item name="windowSplashScreenAnimatedIcon">@mipmap/ic_launcher_foreground</item>
</style>

And to finish, my dialog fragment is the same XML using everywhere in my app with padding in a RelativeLayout :

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingStart="@dimen/activity_horizontal_margin"
    android:paddingEnd="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin">

This problem is only for DialogFragment or AlertDialog in the MainActivity, no problem for the other components or DialogFragment in other activities... Any idea ?

CodePudding user response:

I had the same problem. All paddings even inside EditTextfields were gone. In my case it was fitsSystemWindows set to true in the postSplashScreenTheme.

Setting

fitsSystemWindows = false

solved the problem for me.

  • Related