实现新 API SplashScreen 后 DialogFragment 的边距/填充问题

问题描述 投票:0回答:2

我在我的应用程序上添加了新的 Splashscreen API (androidx.core:core-splashscreen:1.0.0-rc01),之后我的边距/填充被破坏,但仅适用于我的启动器活动 (MainActivity),特别是从此打开的对话框片段活动。在其他活动中,没问题,一切正常。

下面,我的对话框片段没有实现启动画面,我的填充/边距都正常:

现在有了闪屏实现:

[Margin and padding broken withSplashscreen2

我按照开发人员 Android 文档的说明进行操作:https://developer.android.com/reference/kotlin/androidx/core/splashscreen/SplashScreen

在我的 MainActivy.kt 中

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

在 Manifest.xml 中,我在 MainActity 中添加了以下代码

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

在我的 Splashscreen 主题中,我已将“postSplashScreenTheme”设置为我的原始主题

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

最后,我的对话框片段是在我的应用程序中随处使用的相同 XML,并在相对布局中进行填充:

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

此问题仅针对 MainActivity 中的 DialogFragment 或 AlertDialog,其他组件或其他 Activity 中的 DialogFragment 没有问题... 有什么想法吗?

android kotlin android-layout android-actionbar padding
2个回答
5
投票

我也有同样的问题。甚至在 EditTextfields 内的所有填充都消失了。 就我而言,它在 postSplashScreenTheme 中设置为 true。

设置

fitsSystemWindows = false

解决了我的问题。


0
投票

Hiede 的解决方案一开始对我不起作用。我需要更改父项以匹配我的 Material3 并添加该项目

 <style name="Theme.App.Starting" parent="Theme.SplashScreen.IconBackground">
    <item name="windowSplashScreenBackground">@color/bg_splash</item>
    <item name="windowSplashScreenAnimatedIcon">@drawable/ic_launcher_foreground</item>
    <!-- Set the theme of the Activity that directly follows splash screen. -->
    <item name="postSplashScreenTheme">@style/postSplashTheme</item>
</style>

<style name="postSplashTheme" parent="@style/Theme.Material3.Dark.NoActionBar">
    <item name="android:fitsSystemWindows">false</item>
</style>
© www.soinside.com 2019 - 2024. All rights reserved.